Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pinkhominid/network-event
A global normalized event for browser network requests (fetch & XHR).
https://github.com/pinkhominid/network-event
browser event network request
Last synced: 27 days ago
JSON representation
A global normalized event for browser network requests (fetch & XHR).
- Host: GitHub
- URL: https://github.com/pinkhominid/network-event
- Owner: pinkhominid
- License: mit
- Created: 2020-01-25T18:45:53.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-04T03:22:47.000Z (almost 4 years ago)
- Last Synced: 2024-04-25T11:03:25.232Z (9 months ago)
- Topics: browser, event, network, request
- Language: JavaScript
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Network Event
A global normalized event for browser network requests (fetch & XHR).
```sh
npm i network-event
``````js
import { NETWORK_EVENT, PENDING_STATE, COMPLETE_STATE } from 'network-event';window.addEventListener(NETWORK_EVENT, async e => {
switch (e.detail.state) {
case PENDING_STATE: console.log(e.detail); break;
case COMPLETE_STATE: console.log(e.detail, await e.detail.json()); break;
}
});fetch('https://jsonplaceholder.typicode.com/users');
const req = new XMLHttpRequest();
req.open('get', 'https://jsonplaceholder.typicode.com/users');
req.send();
``````sh
▸ Object { state: "pending", url: "https://jsonplaceholder.typicode.com/users" }▸ Object { state: "pending", url: "https://jsonplaceholder.typicode.com/users" }
▸ Object { state: "complete", url: "https://jsonplaceholder.typicode.com/users", status: 200, "content-type": "application/json; charset=utf-8", text: send(), json: send() }
▸ Array(10) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…} ]▸ Object { state: "complete", url: "https://jsonplaceholder.typicode.com/users", status: 200, "content-type": "application/json; charset=utf-8", text: fetch(), json: fetch() }
▸ Array(10) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…} ]
```