{"name":"wreck","description":"HTTP Client Utilities","version":"6.3.0","repository":{"type":"git","url":"git://github.com/hapijs/wreck"},"main":"lib/index","keywords":["utilities","http","client"],"engines":{"node":">=0.10.40"},"dependencies":{"hoek":"2.x.x","boom":"2.x.x"},"devDependencies":{"lab":"5.x.x","code":"1.x.x"},"scripts":{"test":"lab -t 100 -L -a code","test-cov-html":"lab -r html -o coverage.html -a code"},"license":"BSD-3-Clause","readme":"![wreck Logo](https://raw.github.com/hapijs/wreck/master/images/wreck.png)\n\nHTTP Client Utilities\n\n[![Build Status](https://secure.travis-ci.org/hapijs/wreck.png)](http://travis-ci.org/hapijs/wreck)\n\nLead Maintainer: [Wyatt Preul](https://github.com/geek)\n\n## Usage\n\n### Basic\n```javascript\nvar Wreck = require('wreck');\n\nWreck.get('https://google.com/', function (err, res, payload) {\n    /* do stuff */\n});\n```\n\n### Advanced\n```javascript\nvar Wreck = require('wreck');\n\nvar method = 'GET'; // GET, POST, PUT, DELETE\nvar uri    = 'https://google.com/';\nvar readableStream = Wreck.toReadableStream('foo=bar');\n\nvar wreck = Wreck.defaults({\n    headers: { 'x-foo-bar': 123 }\n});\n\n// cascading example -- does not alter `wreck`\nvar wreckWithTimeout = wreck.defaults({\n    timeout: 5\n});\n\n// all attributes are optional\nvar options = {\n    baseUrl:   fully qualified uri string used as the base url. Most useful with `request.defaults`, for example when you want to do many requests to the same domain.\n               If `baseUrl` is `https://example.com/api/`, then requesting `/end/point?test=true` will fetch `https://example.com/api/end/point?test=true`. Any\n               querystring in the `baseUrl` will be overwritten with the querystring in the `uri` When `baseUrl` is given, `uri` must also be a string.\n    payload:   readableStream || 'foo=bar' || new Buffer('foo=bar'),\n    headers:   { /* http headers */ },\n    redirects: 3,\n    beforeRedirect: function (redirectMethod, statusCode, location, redirectOptions) {},\n    redirected: function (statusCode, location, req) {},\n    timeout:   1000,    // 1 second, default: unlimited\n    maxBytes:  1048576, // 1 MB, default: unlimited\n    rejectUnauthorized: true || false,\n    downstreamRes: null,\n    agent: null,         // Node Core http.Agent\n    secureProtocol: 'SSLv3_method' // The SSL method to use\n};\n\nvar optionalCallback = function (err, res) {\n\n    /* handle err if it exists, in which case res will be undefined */\n\n    // buffer the response stream\n    Wreck.read(res, null, function (err, body) {\n        /* do stuff */\n    });\n};\n\nvar req = wreck.request(method, uri, options, optionalCallback);\n```\n\n### `defaults(options)`\n\nReturns a *new* instance of Wreck which merges the provided `options` with those provided on a per-request basis. You can call defaults repeatedly to build up multiple http clients.\n- `options` - Config object containing settings for both `request` and `read` operations.\n\n### `request(method, uri, [options, [callback]])`\n\nInitiate an HTTP request.\n- `method` - A string specifying the HTTP request method, defaulting to 'GET'.\n- `uri` - The URI of the requested resource.\n- `options` - An optional configuration object. To omit this argument but still\n  use a callback, pass `null` in this position. The options object supports the\n  following optional keys:\n    - `payload` - The request body as string, Buffer, or Readable Stream.\n    - `headers` - An object containing request headers.\n    - `rejectUnauthorized` - [TLS](http://nodejs.org/api/tls.html) flag indicating\n      whether the client should reject a response from a server with invalid certificates.  This cannot be set at the\n      same time as the `agent` option is set.\n    - `redirects` - The maximum number of redirects to follow.\n    - `beforeRedirect` - A callback function that is called before a redirect is triggered, using the signature function (redirectMethod, statusCode, location, redirectOptions) where:\n      - `redirectMethod` - A string specifying the redirect method.\n      - `statusCode` - HTTP status code of the response that triggered the redirect.\n      - `location` - The redirect location string.\n      - `redirectOptions` - Options that will be applied to the redirect request.\n    - `redirected` - A callback function that is called when a redirect was triggered, using the signature `function (statusCode, location, req)` where:\n      - `statusCode` - HTTP status code of the response that triggered the redirect.\n      - `location` - The redirected location string.\n      - `req` - The new [ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest) object which replaces the one initially returned.\n    - `agent` - Node Core [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent).\n      Defaults to either `wreck.agents.http` or `wreck.agents.https`.  Setting to `false` disables agent pooling.\n    - `timeout` - The number of milliseconds to wait without receiving a response\n      before aborting the request. Defaults to unlimited.\n    - `secureProtocol` - [TLS](http://nodejs.org/api/tls.html) flag indicating the SSL method to use, e.g. `SSLv3_method`\n      to force SSL version 3. The possible values depend on your installation of OpenSSL. Read the official OpenSSL docs\n      for possible [SSL_METHODS](http://www.openssl.org/docs/ssl/ssl.html#DEALING_WITH_PROTOCOL_METHODS).\n- `callback` - The optional callback function using the signature `function (err, response)` where:\n    - `err` - Any error that may have occurred during the handling of the request.\n    - `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)\n       object, which is also a readable stream.\n\nReturns an instance of the node.js [ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest) object.\n\n\n### `read(response, options, callback)`\n- `response` - An HTTP Incoming Message object.\n- `options` - `null` or a configuration object with the following optional keys:\n    - `timeout` - The number of milliseconds to wait while reading data before\n    aborting handling of the response. Defaults to unlimited.\n    - `json` - A value indicating how to try to parse the payload as JSON. Defaults to `undefined` meaning no parse logic.\n        - `true`, 'smart' - only try `JSON.parse` if the response indicates a JSON content-type.\n        - `force` - try `JSON.parse` regardless of the content-type header.\n    - `maxBytes` - The maximum allowed response payload size. Defaults to unlimited.\n- `callback` - The callback function using the signature `function (err, payload)` where:\n    - `err` - Any error that may have occurred while reading the response.\n    - `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).\n\n\n### `get(uri, [options], callback)`\n\nConvenience method for GET operations.\n- `uri` - The URI of the requested resource.\n- `options` - Optional config object containing settings for both `request` and\n  `read` operations.\n- `callback` - The callback function using the signature `function (err, response, payload)` where:\n    - `err` - Any error that may have occurred during handling of the request.\n    - `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)\n       object, which is also a readable stream.\n    - `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).\n\nReturns an instance of the node.js [ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest) object.\n\n\n### `post(uri, [options], callback)`\n\nConvenience method for POST operations.\n- `uri` - The URI of the requested resource.\n- `options` - Optional config object containing settings for both `request` and\n  `read` operations.\n- `callback` - The callback function using the signature `function (err, response, payload)` where:\n    - `err` - Any error that may have occurred during handling of the request.\n    - `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)\n       object, which is also a readable stream.\n    - `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).\n\nReturns an instance of the node.js [ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest) object.\n\n### `patch(uri, [options], callback)`\n\nConvenience method for PATCH operations.\n- `uri` - The URI of the requested resource.\n- `options` - Optional config object containing settings for both `request` and\n  `read` operations.\n- `callback` - The callback function using the signature `function (err, response, payload)` where:\n    - `err` - Any error that may have occurred during handling of the request.\n    - `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)\n       object, which is also a readable stream.\n    - `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).\n\nReturns an instance of the node.js [ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest) object.\n\n\n### `put(uri, [options], callback)`\n\nConvenience method for PUT operations.\n- `uri` - The URI of the requested resource.\n- `options` - Optional config object containing settings for both `request` and\n  `read` operations.\n- `callback` - The callback function using the signature `function (err, response, payload)` where:\n    - `err` - Any error that may have occurred during handling of the request.\n    - `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)\n       object, which is also a readable stream.\n    - `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).\n\nReturns an instance of the node.js [ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest) object.\n\n\n### `delete(uri, [options], callback)`\n\nConvenience method for DELETE operations.\n- `uri` - The URI of the requested resource.\n- `options` - Optional config object containing settings for both `request` and\n  `read` operations.\n- `callback` - The callback function using the signature `function (err, response, payload)` where:\n    - `err` - Any error that may have occurred during handling of the request.\n    - `response` - The [HTTP Incoming Message](http://nodejs.org/api/http.html#http_http_incomingmessage)\n       object, which is also a readable stream.\n    - `payload` - The payload in the form of a Buffer or (optionally) parsed JavaScript object (JSON).\n\nReturns an instance of the node.js [ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest) object.\n\n\n### `toReadableStream(payload, [encoding])`\n\nCreates a [readable stream](http://nodejs.org/api/stream.html#stream_class_stream_readable)\nfor the provided payload and encoding.\n- `payload` - The Buffer or string to be wrapped in a readable stream.\n- `encoding` - The encoding to use. Must be a valid Buffer encoding, such as 'utf8' or 'ascii'.\n\n```javascript\nvar stream = Wreck.toReadableStream(new Buffer('Hello', 'ascii'), 'ascii');\nvar read = stream.read();\n// read -> 'Hello'\n```\n\n### `parseCacheControl(field)`\n\nParses the provided *cache-control* request header value into an object containing\na property for each directive and it's value. Boolean directives, such as \"private\"\nor \"no-cache\" will be set to the boolean `true`.\n- `field` - The header cache control value to be parsed.\n\n```javascript\nvar  result = Wreck.parseCacheControl('private, max-age=0, no-cache');\n// result.private -> true\n// result['max-age'] -> 0\n// result['no-cache'] -> true\n```\n\n### `agents`\n\nObject that contains the agents for pooling connections for `http` and `https`.  The properties are `http`, `https`, and\n`httpsAllowUnauthorized` which is an `https` agent with `rejectUnauthorized` set to true.  All agents have `maxSockets`\nconfigured to `Infinity`.  They are each instances of the node.js\n[Agent](http://nodejs.org/api/http.html#http_class_http_agent) and expose the standard properties.\n\nFor example, the following code demonstrates changing `maxSockets` on the `http` agent.\n\n ```js\n var Wreck = require('wreck');\n\n Wreck.agents.http.maxSockets = 20;\n ```\n\n\n### Events\n\n#### `response`\n\nThe response event is always emitted for any request that *wreck* makes.  The handler should accept the following\narguments `(error, request, response, start, uri)` where:\n  - `error` - a Boom error\n  - `request` - the raw `ClientHttp` request object\n  - `response` - the raw `IncomingMessage` response object\n  - `start` - the time that the request was initiated\n  - `uri` - the result of `Url.parse(uri)`. This will provide information about the resource requested.  Also includes\n    the headers and method.\n\nThis event is useful for logging all requests that go through *wreck*.\nThe error and response arguments can be undefined depending on if an error occurs.  Please be aware that if multiple\nmodules are depending on the same cached *wreck* module that this event can fire for each request made across all\nmodules.  The start argument is the timestamp when the request was started.  This can be useful for determining how long\nit takes *wreck* to get a response back and processed.\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/hapijs/wreck/issues"},"homepage":"https://github.com/hapijs/wreck","_id":"wreck@6.3.0","_shasum":"a1369769f07bbb62d6a378336a7871fc773c740b","_from":"https://registry.npmjs.org/wreck/-/wreck-6.3.0.tgz","_resolved":"https://registry.npmjs.org/wreck/-/wreck-6.3.0.tgz"}