1 | ziti-electron-fetch
|
2 | ===================
|
3 |
|
4 | [![npm version][npm-image]][npm-url]
|
5 | [![build status][travis-image]][travis-url]
|
6 | [![install size][install-size-image]][install-size-url]
|
7 |
|
8 | A module that intercepts all `window.fetch` calls in the web-app loaded within an Electron Renderer process, and routes those HTTP/REST calls over a Ziti network.
|
9 |
|
10 |
|
11 |
|
12 | - [Motivation](#motivation)
|
13 | - [Features](#features)
|
14 | - [Difference from client-side fetch](#difference-from-client-side-fetch)
|
15 | - [Installation](#installation)
|
16 | - [Loading and configuring the module](#loading-and-configuring-the-module)
|
17 | - [License](#license)
|
18 | - [Acknowledgement](#acknowledgement)
|
19 |
|
20 |
|
21 |
|
22 | ## Motivation
|
23 |
|
24 | Instead of implementing `XMLHttpRequest` in Node.js to run browser-specific [Fetch polyfill](https://github.com/github/fetch), why not go from native `http` to `fetch` API directly? Hence, `ziti-electron-fetch`, minimal code for a `window.fetch` compatible API on Node.js runtime.
|
25 |
|
26 |
|
27 | ## Features
|
28 |
|
29 | - Stay consistent with `window.fetch` API.
|
30 | - Make conscious trade-off when following [WHATWG fetch spec][whatwg-fetch] and [stream spec](https://streams.spec.whatwg.org/) implementation details, document known differences.
|
31 | - Use native promise but allow substituting it with [insert your favorite promise library].
|
32 | - Use native Node streams for body on both request and response.
|
33 | - Useful extensions such as timeout, redirect limit, response size limit, [explicit errors](ERROR-HANDLING.md) for troubleshooting.
|
34 |
|
35 | ## Difference from client-side fetch
|
36 |
|
37 | - See [Known Differences](LIMITS.md) for details.
|
38 | - If you happen to use a missing feature that `window.fetch` offers, feel free to open an issue.
|
39 | - Pull requests are welcomed too!
|
40 |
|
41 | ## Installation
|
42 |
|
43 | ```sh
|
44 | $ npm install ziti-electron-fetch
|
45 | ```
|
46 |
|
47 | ## Loading and configuring the module
|
48 | We suggest you load the module via `require` until the stabilization of ES modules in node:
|
49 | ```js
|
50 | const fetch = require('ziti-electron-fetch');
|
51 | ```
|
52 |
|
53 |
|
54 | ## Acknowledgement
|
55 |
|
56 | Thanks to [node-fetch](https://github.com/node-fetch/node-fetch) for providing a solid implementation reference.
|
57 |
|
58 | ## License
|
59 |
|
60 | Apache 2.0
|
61 |
|
62 | [npm-image]: https://flat.badgen.net/npm/v/ziti-electron-fetch
|
63 | [npm-url]: https://www.npmjs.com/package/ziti-electron-fetch
|
64 | [travis-image]: https://flat.badgen.net/travis/netfoundry/ziti-electron-fetch
|
65 | [travis-url]: https://travis-ci.org/netfoundry/ziti-electron-fetch
|
66 | [install-size-image]: https://flat.badgen.net/packagephobia/install/ziti-electron-fetch
|
67 | [install-size-url]: https://packagephobia.now.sh/result?p=ziti-electron-fetch
|
68 | [whatwg-fetch]: https://fetch.spec.whatwg.org/
|
69 | [response-init]: https://fetch.spec.whatwg.org/#responseinit
|
70 | [node-readable]: https://nodejs.org/api/stream.html#stream_readable_streams
|
71 | [mdn-headers]: https://developer.mozilla.org/en-US/docs/Web/API/Headers
|
72 | [LIMITS.md]: https://github.com/netfoundry/ziti-electron-fetch/blob/master/LIMITS.md
|
73 | [ERROR-HANDLING.md]: https://github.com/netfoundry/ziti-electron-fetch/blob/master/ERROR-HANDLING.md
|