Simplifies node HTTP request making (HTTP client) with caching support.
Requestify is a super easy to use and extendable HTTP client for nodeJS + it supports cache (-:.
npm install requestify
Requestify is extremely easy to use and always return a promise (using the amazing Q module)...
Simply require the module and start requesting:
var requestify = ;
POST Request in JSON:
Sets Requestify's encoding. Requestify will use this encoding to decode the responses. Defaults to utf8.
requestify; // utf8 is set by default anyway.
Sets the cache transporter for Requestify's use. Requestify will use this transporter for caching the desired HTTP responses.
For using one of Requestify's core transporter use the core transporters object (
PLEASE NOTE: the inMemory() transporter is set by default.
var coreCacheTransporters = requestifycoreCacheTransporters;requestify; // set simple in-memory caching (set by default)requestify; // Set the core Redis cache transporter, orrequestify; // set the core Mongo cache transporter
You can implement your own cache transporters (@see docs below)
Sets Redis client instance. Requestify will use that instance for caching responses. Please note, Requestify will NOT cache anything by default and caching is allowed only for GET requests (see @cache options for further info).
PLEASE NOTE, this method is only a shorthand for using
var redis = ;requestify;
HTTP method to use, can be any valid HTTP method (e.g. POST, GET, DELETE, HEAD, PUT, etc.).
Can be either an object (key, val) or a string, will be formatted depending on the dataType property and served via request body.
Object of key-value params, will be encoded to url encoded string and added as the request query string.
(key, value) object of headers (some headers like content-length are set by default)
(key, value) object of cookies to encode and serve via the request header.
Adds Basic authentication header with given username and password
Determines 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).
If null will be given, the body will be served as string.
Set a timeout (in milliseconds) for the request.
Determines if should continue with redirects
Requistify has built-in Redis based caching mechanism. For using this feature, set the cache property to true using the following object:
Caching will always be set to
false by default.
Executes a custom request according to options object
Executes a GET method request
Executes a POST method request
Executes a PUT method request
Executes a DELETE method request
Executes a HEAD method request
.then() callback is used for handling succesful responses, the .
fail() callback is used for handling errors.
Using Requestify, you can implement your own cache transporters for using currently unsupported stores. To 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). Below is the interface specs to implement:
Returns the response according to the given URL from your cache store and call the given callback with the data.
Store 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.
Purge the response according to the given URL (key) from your cache store.
To run the test suite first install the development dependencies:
$ npm install
Then run the tests:
$ npm test
The MIT License (MIT)
Copyright (c) 2013 Ran Mizrahi <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.