service-client
v0.0.2
Published
javascript wrapper function for http.request and https.request that returns parsed data in callback
Downloads
3
Readme
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
:function
used to parse the raw http result.Given 2 parameters:
buffer
: TheBuffer
that holds the raw http datacallback
: Callbackfunction
taking two paramers (err
,data
)
If
parse
is a string, one of the internal parsers are returned:- "json": wraps
JSON.parse
- "raw": returns the data data as-is
transform
:function
used to transform the parsed data. Given 2 parameters:data
: The data returned from the parse functioncallback
: Callbackfunction
taking two paramers (err
,data
)
parse
andtransform
defaults 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
:null
when 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-length
headerreceived
: The number of bytes received so farbuffer
: TheBuffer
object that is used to hold the raw http dataparsed
: The parsed data
content-length
response header is not present,length
will be-1
(while transfering) or the number of bytesreceived
when theend
event is fireddata
: The transformed data.undefined
if an error has occured.
Dependencies
defaultify
Handles options setup for get defaultify on npm