0.1.1 • Published 5 years ago
@emdc/requester v0.1.1
@emdc/requester
Deps
@babel/core ^7.5.5
,@babel/plugin-proposal-decorators ^7.6.0
,isomorphic-fetch ^2.2.1
,js-cookie ^2.2.1
,normalize-url ^4.5.0
.
Required config for @babel/plugin-proposal-decorators
:
"plugins": [
// other plugins
["@babel/plugin-proposal-decorators", {"legacy": true}]
]
And see official documentation.
Example in browser
You can see library at work with example. Run command npm start
and open link http://localhost:3000/
.
Simple code example
import Requester from '@emdc/requester';
const tasksClient = new Requester('https://jsonplaceholder.typicode.com/todos');
// Using
tasksClient
.get('/1')
.then((resp) => console.log(resp));
// or
const showTaskById = async (id) => {
const task = await tasksClient.get(`/${id}`);
console.log(task);
};
const TASK_ID = 1;
showTaskById(TASK_ID);
Description
Constructor parameters
host
.protocol
. Default ishttps
. You can useProtocol
by importimport {Protocol} from '@emdc/requester';
.timeout
, ms. Default is10000
.useAuthorization
. Default isfalse
. By this params library get token from cookies.
Methods
get(url, query)
.post(url, body = {}, query = {})
.put(url, body = {}, query = {})
.delete(url, query = {})
.
Properties
checkPerformance
,true/false
. Default value isfalse
.checkPerformanceCallback
. You can use cb by template:(time, requestParameters) => {...}
. Default callback is() => null
.