simple-json-request v1.0.0
simple-json-request
A simple module to make json requests with Promise support, that wraps around the simple-get module.
Installation
npm install simple-json-requestUsage
const request = require('simple-json-request')
request.request({
method: 'GET',
url: 'http://example.com'
})
.then((data) => {
// ...
})
.catch((error) => {
// ...
});API
request(options)
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.
get(options)
A convenience function that uses the method GET by default.
post(options)
A convenience function that uses the method POST by default.
put(options)
A convenience function that uses the method PUT by default.
delete(options)
A convenience function that uses the method DELETE by default.
head(options)
A convenience function that uses the method HEAD by default.
patch(options)
A convenience function that uses the method PATCH by default.
options
url
The url to request.
method
The http method. Supports GET, POST, PUT, PATCH, HEAD and DELETE.
timeout
Allows to set a socket timeout in milliseconds.
headers
Allows to pass headers with the request.
body
The body of a post request.
form
The form data of a post request with Content-Type : application/x-www-form-urlencoded.
readTimeout
Allows to set a read timeout in milliseconds.
maxRedirects
The maximum number of redirects to follow in a request. Defaults to 10.
parser
Allows to specify a custom json parser like turbo-json-parse.