@w4spe/request-service
v1.1.0
Published
Simple node (v7.7.4+ required) request library.
Downloads
4
Readme
request-service
Simple node (v7.7.4+ required) request library.
Installation
$ npm i -S @w4spe/request-service
Requirements
All functions set a bearer token by default, you must add BEARER_TOKEN
to
your environment variables or pass it as argument when requiring the module.
Asynchronous example
const requestService = require('@w4spe/requestService')();
async function doSomething (data) {
// Result contains the returned value by the API.
const result = await requestService.post('api/do/something', data);
return await requestService.get('api/get/anything');
}
Synchronous example
const requestService = require('@w4spe/requestService')();
function doSomething (data) {
// Result contains the returned value by the API.
const result = requestService.postSync('api/do/something', data);
return requestService.getSync('api/get/anything');
}
API
The following are the available functions:
- get
- getSync
- post
- postSync
- put
- putSync
- delete
- deleteSync
And their parameters:
- url: URL to use, required
- data: Data to add to body request, optional
- isJSON: Whether to add the data as JSON data or as URL encoded forms, optional
- useToken: Whether to add the authentication header