1.0.5 • Published 5 years ago
fw-fetch-wrapper v1.0.5
FetchWrapper - is a wrapper to allow interaction with fetch.
$ npm install fw-fetch-wrapper
import {FetchWrapper} from 'fw-fetch-wrapper';
const myFetch = new FetchWrapper();
myFetch.configure({
baseURL: 'https://exampleFetchWrapper.com',
headers: {
'Content-Type': 'application/json',
},
});
Create own class with the specified parameters
class MyFetch {
static async requsetTo() {
const response = await myFetch.send(
myFetch.sendRequest()
);
return await response.getContent();
}
}
Call the method and process the result
MyFetch.requsetTo().then(data => console.log(data));
class MyFetch {
static async requsetTo() {
const response = await myFetch.send(
myFetch.sendRequest()
.url('/exampleUrl') // https://exampleFetchWrapper.com/exampleUrl
.params({
id: 14,
userName: 'Protonko',
}) // https://exampleFetchWrapper.com/exampleUrl?id=14&userName=Protonko
.method('POST') // *GET, POST, PUT, DELETE, etc.
.body({id: 1, answer: 42}) // body data type must match "Content-Type" header
.addHeader('name', 'value')
.removeHeader('name')
);
return await response.getContent();
}
}