A light, fluent node.js HTTP client for ES6.
Heavily inspired by superagent
as well as fetch.
Designed with ES7 async/await in mind.
The API is quite minimal for now.
Features will be added while people request or use them.
var req = require('requisition');// GET a JSON bodyasync function () { var res = await req('/users.json'); var body = await res.json();}// POST an image fileasync function () { var res = await req.post('/images.json').sendFile('image.png'); var body = await res.json();}
Differences
This is similar to other AJAX libraries like axios except:
Does not have browser support
Does not depend on gigantic options objects
Many utilities for handling HTTP responses like saving to a file
Infer the Content-Type of the response,
similar to Koa or Express' method.
See type-is.
response.get(header)
Get the value for a header.
response.charset
Get charset.
response.etag
Get header ETag.
response.lastModified
Get header Last-Modified.
response.cookies
Get cookies
request('/cookie').then(function (response) { console.info(response.cookies);})#### response.buffer().then( buffer => )Return a single `Buffer` for the entire response.#### response.text().then( text => )Return a single `String` for the entire response.#### response.json().then( body => )Automatically parse the JSON of the response.```jsrequest('/users.json').then(function (response) { assert(response.status === 200, 'Bad response!'); assert(response.is('json'), 'Bad type!'); return response.json()
response.saveTo([filename]).then( filename => )
Save the response to a file.
If no filename is specified,
saves to a random file in your temporary directory.