client-side request module
Agent is a client-side request module inspired by SuperAgent.
var agent =var request =
Agent can be used by composing methods:
These methods also act as getters when no parameter is supplied.
Agent can also be used by passing arguments:
var request =// defaults to POSTvar request =// defaults to POST, no datavar request =
You can also mix and match:
var request =request
request // set request headerrequest // get request headerrequest // get all request headerrequest // boolrequest // duhrequestrequest // don't use "password" as your password
Agent encodes data you send and decodes data it receives based on content-type.
By default, it encodes and decodes
application/json (however an
application/x-www-form-urlencoded response is not common).
You can add a new response body decoder by doing:
Or an encoder for data you send:
// This is already in Agent, this is an exampleagent;request// the request will be sent with JSON rather than url encoded.requestdataa: 1 b: 2
The response obejct you get back when requesting contains a few useful properties:
responsetext // response textresponsebody // parsed response text based on the content-type header fieldresponsestatus // response statusresponseheader // response header, as an object// and some added sugar, courtesy of SuperAgentresponseinforesponseokresponseclientErrorresponseserverErrorresponseerrorresponseacceptedresponsenoContentresponsebadRequestresponseunauthorizedresponsenotAcceptableresponsenotFound
And fire up a browser on