A simple module to make json requests with Promise support, that wraps around the simple-get module.
npm install simple-json-request
const request = require('simple-json-request')
request.request({
method: 'GET',
url: 'http://example.com'
})
.then((data) => {
// ...
})
.catch((error) => {
// ...
});
Executes a request with the specified options
. options
may be a string representing a url. Returns a promise that either resolves the parsed data or rejects with an error.
A convenience function that uses the method GET
by default.
A convenience function that uses the method POST
by default.
A convenience function that uses the method PUT
by default.
A convenience function that uses the method DELETE
by default.
A convenience function that uses the method HEAD
by default.
A convenience function that uses the method PATCH
by default.
The url to request.
The http method. Supports GET
, POST
, PUT
, PATCH
, HEAD
and DELETE
.
Allows to set a socket timeout in milliseconds.
Allows to pass headers with the request.
The body of a post request.
The form data of a post request with Content-Type
: application/x-www-form-urlencoded
.
Allows to set a read timeout in milliseconds.
The maximum number of redirects to follow in a request. Defaults to 10
.
Allows to specify a custom json parser like turbo-json-parse.