Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/omgimalexis/interception
https://github.com/omgimalexis/interception
Last synced: 29 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/omgimalexis/interception
- Owner: OmgImAlexis
- License: mit
- Created: 2021-01-15T05:49:33.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-24T19:57:06.000Z (almost 4 years ago)
- Last Synced: 2024-10-14T07:53:48.464Z (about 1 month ago)
- Language: TypeScript
- Size: 115 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Inception
Interceptor library for the native fetch module inspired by [fetch-intercept](https://github.com/werk85/fetch-intercept).
`interception` returns a patched `fetch` method.
## Installation
```
npm install github:OmgImAlexis/interception#main --save
```## Usage
```ts
import nodeFetch from 'node-fetch';
import { attach } from 'interception';const { register, fetch } = attach(nodeFetch);
const unregister = register({
request: function (url, config) {
// Modify the url or config here
return [url, config];
},requestError: function (error) {
// Called when an error occured during another 'request' interceptor call
return Promise.reject(error);
},response: function (response) {
// Modify the reponse object
return response;
},responseError: function (error) {
// Handle a fetch error
return Promise.reject(error);
}
});// Call fetch to see your interceptors in action.
fetch('http://google.com');// Unregister your interceptor
unregister();
```## License
MIT