fetchagent
v2.1.1
Published
Flex API for global fetch
Downloads
49
Maintainers
Readme
fetchagent
Flex API for global fetch
Install
$ npm install --save fetchagent
Usage
var fa = require('fetchagent');
// using callbacks
fa
.get('http://httpbin.org/xml')
.end(function(err, response) {
if (err) {
console.log(err, status);
}
console.log("Received:", response);
});
// using promises
fa
.post('http://httpbin.org/post')
.send({ echo: 42 })
.json()
.then(function(response) {
console.log("Received:", response.echo);
});
API
To configure request use one or more:
get(url)
,put(url)
,post(url)
,delete(url)
- HTTP method tourl
query()
- sets search params (a.k.a querystring)set(name, vale)
- sets headername
tovalue
set(obj)
- sets headers for all properties of theobject
redirect(flag)
- pass truthy value if fetchagent is supposed to automatically handle redirects
To send request use on of:
end(callback)
- passcallback(err, body)
end()
- returns a Promise that resolves to a responsejson()
- returns a Promise resolving to a parsed objecttext()
- returns a Promise resolving to a body text
License
MIT © Damian Krzeminski