-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.json
57 lines (57 loc) · 9.04 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{
"name": "requestify",
"description": "Simplifies node HTTP request making (HTTP client) with caching support.",
"version": "0.1.16",
"scripts": {
"test": "mocha -R spec test/**/*.js test/*.js"
},
"license": "MIT",
"tags": [
"http",
"request",
"http-request",
"simple",
"web services",
"util",
"http client",
"client",
"request client",
"http cache",
"cache",
"HTTP caching"
],
"author": {
"name": "Ran Mizrahi",
"email": "ranm@codeoasis.com"
},
"dependencies": {
"q": "~0.9.3",
"underscore": "~1.4.4",
"jquery": "~1.8.3"
},
"devDependencies": {
"mocha": "~1.9.0",
"chai": "~1.6.1",
"sinon": "~1.7.2",
"rewire": "~1.1.3"
},
"repository": {
"type": "git",
"url": "https://github.com/ranm8/requestify.git"
},
"engines": {
"node": "~0.10.x"
},
"readme": "Requestify - Simplifies node HTTP request making. [![Build Status](https://secure.travis-ci.org/ranm8/requestify.png?branch=master)](http://travis-ci.org/ranm8/requestify)\n==============================================\n\nRequestify is a super easy to use and extendable HTTP client for nodeJS + it supports cache (-:.\n\n## Installation\n\n\tnpm install requestify \n\n## How to use?\n\nRequestify is extremely easy to use and always return a promise (using the amazing Q module)...\n\nSimply require the module and start requesting:\n\n``` javascript\nvar requestify = require('requestify'); \n```\nGET Request:\n\n``` javascript\nrequestify.get('http://example.com').then(function(response) {\n\t// Get the response body\n\tresponse.getBody();\n});\n```\n\nPOST Request in JSON:\n\n``` javascript\nrequestify.post('http://example.com', {\n\t\thello: 'world'\n\t})\n\t.then(function(response) {\n\t\t// Get the response body (JSON parsed or jQuery object for XMLs)\n\t\tresponse.getBody();\n\t\t\n\t\t// Get the raw response body\n\t\tresponse.body;\n\t});\n```\n\n## Configuration methods\n\n### requestify.setEncoding(encoding)\n\nSets Requestify's encoding. Requestify will use this encoding to decode the responses.\nDefaults to utf8.\n\n```javascript\nrequestify.setEncoding('utf8'); // utf8 is set by default anyway.\n```\n\n### requestify.cacheTransporter(cacheTransporter)\n\nSets the cache transporter for Requestify's use. Requestify will use this transporter for caching desired flagged HTTP responses.\nFor using one of Requestify's core transporter use the core transporters object (`coreCacheTransporters`).\n\nFor example:\n\n```javascript\nrequestify.cacheTransporter(coreCacheTransporters.redis(myRedisInstance)); // Set the core Redis cache transporter\n```\n\nYou can implement your own cache transporters (@see docs below)\n\n### requestify.redis(redisInstance) - @depercated\n\nSets Redis client instance. Requestify will use that instance for caching responses.\nPlease note, Requestify will NOT cache anything by default and caching is allowed only for GET requests (see @cache options for further info).\n\nPLEASE NOTE, this method is only a shorthand for using `requestify.cacheTransporter(coreCacheTransporters.redis(myRedisInstance));`\n\n```javascript\nvar redis = require('redis');\n\nrequestify.redis(redis.createClient());\n```\n\n## API Reference\n\n### options\n\n#### `method {string}` \nHTTP method to use, can be any valid HTTP method (e.g. POST, GET, DELETE, HEAD, PUT, etc.).\n\n#### `body {object|string}`\nCan be either an object (key, val) or a string, will be formatted depending on the dataType property and served via request body.\n\n#### `params {object}`\nObject of key-value params, will be encoded to url encoded string and added as the request query string.\n\n#### `headers {object}` \n(key, value) object of headers (some headers like content-length are set by default)\n\n#### `cookies {object}` \n(key, value) object of cookies to encode and serve via the request header.\n\n#### `auth {{ username: string, password: string }} `\nAdds Basic authentication header with given username and password\n\n#### `dataType {string}` \nDetermines the request data type (json|form-url-encoded), this option will encode the request body according to the given dataType and will add the appropriate header (defaults to json). \n\nIf null will be given, the body will be served as string.\n\n#### `timeout {number} `\nSet a timeout (in milliseconds) for the request.\n\n#### `cache {{ cache: boolean, expires: number }}`\nRequistify has built-in Redis based caching mechanism. For using this feature, set the cache property to true using the following object:\n\n```javascript\n{\n\tcache: true, // Will set caching to true for this request.\n\texpires: 3600 // Time for cache to expire in seconds\n}\n```\n\nCaching will always be set to `false` by default.\n\n\n### requestify.request(url, options)\n\nExecutes a custom request according to options object\n\n``` javascript\nrequestify.request('https://example.com/api/foo', {\n\tmethod: 'POST',\n\tbody: {\n\t\tfoo: 'bar'\n\t\tbar: 'foo'\n\t},\n\theaders: {\n\t\t'X-Forwarded-By': 'me'\n\t},\n\tcookies: {\n\t\tmySession: 'some cookie value'\n\t},\n\tauth: {\n\t\tusername: 'foo',\n\t\tpassword: 'bar'\n\t},\n\tdataType: 'json'\t\t\n})\n.then(function(response) {\n\t// get the response body\n\tresponse.getBody();\n\n \t// get the response headers\n \tresponse.getHeaders();\n\n \t// get specific response header\n \tresponse.getHeader('Accept');\n \n \t// get the code\n \tresponse.getCode();\n\t\n\t// get the raw response body\n\tresponse.body;\n});\n```\n### requestify.get(url, options)\n\nExecutes a GET method request\n``` javascript\nrequestify.get('http://example.com').then(function(response) {\n\t// Get the response body\n\tresponse.getBody();\n});\n```\n### requestify.post(url, data, options)\n\nExecutes a POST method request\n``` javascript\nrequestify.post('http://example.com', {\n\t\thello: 'world'\n})\n.then(function(response) {\n\t// Get the response body\n\tresponse.getBody();\n});\n```\n\n### requestify.put(url, data, options)\n\nExecutes a PUT method request\n\n``` javascript\nrequestify.put('http://example.com', 'some-file-content').then(function(response) {\n\t// Get the response body\n\tresponse.getBody();\n});\n```\n\n### requestify.delete(url, options)\n\nExecutes a DELETE method request\n\n``` javascript\nrequestify.delete('http://example.com').then(function(response) {\n\t// Get the response body\n\tresponse.getBody();\n});\n```\n\n### requestify.head(url, options)\n\nExecutes a HEAD method request\n\n``` javascript\nrequestify.head('http://example.com').then(function(response) {\n\t// Get the response code\n\tresponse.getCode();\n});\n```\n\n## Custom Cache Transporters\n\nUsing Requestify, you can implement your own cache transporters for using currently unsupported stores.\nTo implement your own store, all you have to do is implement Requestify's cache transporter interface. For example, you can see the core Redis transporter (./cache-transporters).\nBelow is the interface specs to implement:\n\n### get(url: string, callback: function)\n\nReturns the response according to the given URL from your cache store and call the given callback with the data.\n\n### set(url: string, response: {{ code: number, headers: object, body: string, created: timestamp }}, callback: function)\n\nStore the given response by the given URL (key), please make sure to store the response object exactly in the same way you've got it.\n\n### purge(url: string, callback: function)\n\nPurge the response according to the given URL (key) from your cache store.\n\n## Running Tests\n\nTo run the test suite first install the development dependencies:\n\n\t$ npm install\t\n\nThen run the tests:\n\n\t$ npm test\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Ran Mizrahi <<ranm@codeoasis.com>>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/ranm8/requestify/issues"
},
"homepage": "https://github.com/ranm8/requestify",
"_id": "requestify@0.1.16",
"dist": {
"shasum": "40d710cf3f38e66cd1e477586f7a22a8d96f6838"
},
"_from": "requestify@*",
"_resolved": "https://registry.npmjs.org/requestify/-/requestify-0.1.16.tgz"
}