Simple HTTP API: GET, POST, PUT, DELETE, PATCH
npm install ioio is a simple Node.js HTTP wrapper for API calls.
Methods supported are...
``javascript
const io = require('io');
io.request(method, url, queryParams = {}, headers = null, body = null);
io.get(url, authorization = null, headers = null, queryParams = {});
io.del(url, authorization = null, headers = null, queryParams = {});
io.post(url, authorization = null, headers = null, params = {});
io.put(url, authorization = null, headers = null, params = {});
`
All requests return a Promise and can be run synchronously using await.
`javascript`
let result = await io.request(method, url, queryParams = {}, headers = null, body = null);
The request method takes a raw body string and sends no content-type by default.
It returns a result with the following schema;
`json`
{
"statusCode": 200,
"headers": {},
"body": ""
}
The get and del methods will populate the URL querystring with x-www-urlencodedqueryParams
values based on a object. They will send acontent-type: application/json header by default.
The authorization parameter will set the authorization HTTP header. If thisBasic
value begins with the strings or Bearer , the full value will be used.Bearer
Otherwise, will be prepended. Sending authorization = "x", for example,authorization
will populate the header with a value of Bearer x.
NOTE: If the requested resource does not return JSON data, an error will be thrown.
They return a result with the following schema;
`json`
{
"statusCode": 200,
"headers": {},
"data": {}
}
The post and put methods will populate the post body with application/jsonparams
values based on a object. They will send acontent-type: application/json header by default.
The authorization parameter will set the authorization HTTP header. If thisBasic
value begins with the strings or Bearer , the full value will be used.Bearer
Otherwise, will be prepended. Sending authorization = "x", for example,authorization
will populate the header with a value of Bearer x.
NOTE: If the requested resource does not return JSON data, an error will be thrown.
They return a result with the following schema;
`json``
{
"statusCode": 200,
"headers": {},
"data": {}
}
© 2020 Standard Library (Polybit Inc.)