GithubHelp home page GithubHelp logo

electron-main-fetch's Introduction

electron-main-fetch

Use the browser Fetch API from the main process in Electron

Install

$ npm install electron-main-fetch

Requires Electron 9 or later.

Usage

const fetch = require('electron-main-fetch');

(async () => {
	const response = await fetch('https://api.ipify.org');
	console.log(await response.text());
	//=> '170.56.15.35'
})();

API

fetch(input, options)

Same options as Fetch

Response object example

{
	type: 'cors',
	url: 'https://api.ipify.org/',
	redirected: false,
	status: 200,
	ok: true,
	statusText: 'OK',
	bodyUsed: false,
	headers: {
		keys: [Function],
		entries: [Function],
		values: [Function],
		get: [Function],
		has: [Function],
		set: [Function],
		append: [Function],
		delete: [Function]
	},
	clone: [Function],
	arrayBuffer: [Function],
	json: [Function],
	text: [Function]
}

Difference between this and Fetch

We don't have direct access to the body stream, so there is no body property. There are some methods that are not useful in Node.js, like formData(), redirect(), etc. Some other methods are not very cross-browser compatible, so they are less common to use.

Missing:

  • body
  • blob()
  • formData()
  • error()

A small difference is that our .clone() method is async.

Related

electron-main-fetch's People

Contributors

sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

electron-main-fetch's Issues

Make it work exactly like Fetch

Issuehunt badges

I couldn't make it work exactly the same as Fetch, as the Response object isn't transferred correctly through the Electron IPC. I need to figure out why. Could also maybe use a Proxy to imitate the Response object. Would be really nice if it worked exactly the same. Help welcome :)

Electron issue: electron/electron#9563


IssueHunt Summary

lukks lukks has been rewarded.

Backers (Total: $60.00)

Submitted pull Requests


Tips

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.