service-client v0.0.2
service-client
javascript wrapper function for http.request that returns parsed, transformed data in callback.
API
get(url, options, callback)
url
The URL to access
options
Optional. An object specifying the options for the request, parsing and transformation.
accept: Accept request header (string). Defaults totext/plain- "text" or "plain" are changed to
text/plain - "json" is changed to
application/json
- "text" or "plain" are changed to
parse:functionused to parse the raw http result.Given 2 parameters:
buffer: TheBufferthat holds the raw http datacallback: Callbackfunctiontaking two paramers (err,data)If
parseis a string, one of the internal parsers are returned:"json": wraps
JSON.parse- "raw": returns the data data as-is
transform:functionused to transform the parsed data. Given 2 parameters: -data: The data returned from the parse function -callback: Callbackfunctiontaking two paramers (err,data)parseandtransformdefaults to parsers.plain (returning the data as-is)
callback
The callback function called when an error has occured or when the data was received, parsed and transformed Parameters:
err:nullwhen no error has occured or an error details object with the keys:error: The actual error that was caughtaction: The action where the error occured (request, response, parse, transform)length: The value of thecontent-lengthheaderreceived: The number of bytes received so farbuffer: TheBufferobject that is used to hold the raw http dataparsed: The parsed dataIf the
content-lengthresponse header is not present,lengthwill be-1(while transfering) or the number of bytesreceivedwhen theendevent is fired
data: The transformed data.undefinedif an error has occured.
Dependencies
defaultify
Handles options setup for get defaultify on npm