@gwansikk/server-chain
v0.5.7
Published
The server-chain is a simple and lightweight HTTP Request library.
Downloads
99
Maintainers
Readme
Installation
- NPM
npm i @gwansikk/server-chain
- Yarn
yarn add @gwansikk/server-chain
Usage
Instance
const server = ServerChain({
key: 'INSTANCE',
baseURL: 'https://jsonplaceholder.typicode.com',
});
server.get({ url: 'posts/1' }).then(data => console.log(data));
Interceptor
const server = ServerChain({
key: 'INTERCEPTOR',
baseURL: 'https://jsonplaceholder.typicode.com',
interceptors: {
request: request => {
console.log('** request interceptor **');
// You need to modify the request and return the modified request.
// For example, you can add a specific header to the request or modify the URL.
request.headers = {
...request.headers,
Authorization: 'Bearer YOUR_ACCESS_TOKEN',
};
return request;
},
response: response => {
console.log('** response interceptor **');
// You need to modify the response and return the modified response.
return response;
},
error: response => {
console.log('** error interceptor **');
// You need to modify the error response and return the modified response.
return response;
},
},
});
Roadmap
The list below is a roadmap to get to version 1.0.
- [x] Automatic JSON Conversion
- [x] Instance Creation
- [x] Global Settings
- [x] Request and Response Interceptors
- [ ] Error Status Handling
- [ ] Request Cancellation
- [ ] Progress Bar/Loading Indicator
Contributing
Information describing how to contribute can be found in the file.
CONTRIBUTING.md