Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Fetch | 25,606 | 250,591 | 7,988 | 2 months ago | 33 | February 27, 2021 | 52 | mit | JavaScript | |
A window.fetch JavaScript polyfill. | ||||||||||
Cross Fetch | 1,495 | 14,308 | 1,942 | 25 days ago | 40 | April 10, 2022 | 33 | mit | JavaScript | |
Universal WHATWG Fetch API for Node, Browsers and React Native. | ||||||||||
Eventsource | 702 | 343,320 | 534 | 3 months ago | 35 | June 08, 2022 | 60 | mit | JavaScript | |
EventSource client for Node.js and Browser (polyfill) | ||||||||||
Jscache | 430 | 9 years ago | 1 | mit | JavaScript | |||||
jsCache is a javascript library that enables caching of javascripts, css-stylesheets and images using my localStorage polyfill. This is especially useful when serving your website for mobile phones, which has limited HTTP caching available, but also speeds up your site in an ordinary webbrowser as it saves HTTP requests and loads all files asynchronously. | ||||||||||
Yetch | 161 | 17 | 2 | 3 years ago | 4 | July 13, 2020 | 2 | mit | JavaScript | |
Yet-another-fetch polyfill library. Supports AbortController/AbortSignal | ||||||||||
Fetch | 41 | 17 days ago | 2 | mit | TypeScript | |||||
A Fetch API wrapper | ||||||||||
Whatwg Fetch | 39 | 7 years ago | JavaScript | |||||||
Fork from https://github.com/github/fetch.git | ||||||||||
Chicky | 27 | 6 years ago | JavaScript | |||||||
🐥 window.fetch() api interface | ||||||||||
Hammock | 22 | 190 | 25 | 4 years ago | 29 | May 03, 2019 | JavaScript | |||
Node.js mock http object library for http req / res | ||||||||||
Debug Repo | 18 | 8 months ago | mit | JavaScript | ||||||
This is a debug repo for github-debug.com |
This library is a pure JavaScript implementation of the EventSource client. The API aims to be W3C compatible.
You can use it with Node.js or as a browser polyfill for
browsers that don't have native EventSource
support.
npm install eventsource
npm install
node ./example/sse-server.js
node ./example/sse-client.js # Node.js client
open http://localhost:8080 # Browser client - both native and polyfill
curl http://localhost:8080/sse # Enjoy the simplicity of SSE
Just add example/eventsource-polyfill.js
file to your web page:
<script src=/eventsource-polyfill.js></script>
Now you will have two global constructors:
window.EventSourcePolyfill
window.EventSource // Unchanged if browser has defined it. Otherwise, same as window.EventSourcePolyfill
If you're using webpack or browserify
you can of course build your own. (The example/eventsource-polyfill.js
is built with webpack).
You can define custom HTTP headers for the initial HTTP request. This can be useful for e.g. sending cookies
or to specify an initial Last-Event-ID
value.
HTTP headers are defined by assigning a headers
attribute to the optional eventSourceInitDict
argument:
var eventSourceInitDict = {headers: {'Cookie': 'test=test'}};
var es = new EventSource(url, eventSourceInitDict);
By default, https requests that cannot be authorized will cause the connection to fail and an exception to be emitted. You can override this behaviour, along with other https options:
var eventSourceInitDict = {https: {rejectUnauthorized: false}};
var es = new EventSource(url, eventSourceInitDict);
Note that for Node.js < v0.10.x this option has no effect - unauthorized HTTPS requests are always allowed.
Unauthorized and redirect error status codes (for example 401, 403, 301, 307) are available in the status
property in the error event.
es.onerror = function (err) {
if (err) {
if (err.status === 401 || err.status === 403) {
console.log('not authorized');
}
}
};
You can define a proxy
option for the HTTP request to be used. This is typically useful if you are behind a corporate firewall.
var es = new EventSource(url, {proxy: 'http://your.proxy.com'});
MIT-licensed. See LICENSE