Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

requestify

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

requestify

Simplifies node HTTP request making.

  • 0.1.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.2K
decreased by-10.4%
Maintainers
1
Weekly downloads
 
Created
Source

Requestify - Simplifies node HTTP request making. Build Status

Requestify is a super easy to use and extendable HTTP client for nodeJS.

Installation

npm install requestify  

How to use?

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 = require('requestify'); 

GET Request:

requestify.get('http://example.com').then(function(response) {
	// Get the response body
	response.getBody();
});

POST Request in JSON:

requestify.post('http://example.com', {
		hello: 'world'
	})
	.then(function(response) {
		// Get the response body
		response.getBody();
	});

API Reference

options

method {string}

HTTP method to use, can be any valid HTTP method (e.g. POST, GET, DELETE, HEAD, PUT, etc.).

body {object|string}

Can be either an object (key, val) or a string, will be formatted depending on the dataType property and served via response body.

headers {object}

(key, value) object of headers (some headers like content-length are set by default)

cookies {object}

(key, value) object of cookies to encode and serve via the request header.

auth {{ username: string, password: string }}

Adds Basic authentication header with given username and password

dataType {string}

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.

timeout {number}

Set a timeout (in milliseconds) for the request.

requestify.setEncoding(encoding)

Sets encoding to parse responses with

requestify.request(url, options)

Executes a custom request according to options object

requestify.request('https://example.com/api/foo', {
	method: 'POST',
	body: {
		foo: 'bar'
		bar: 'foo'
	},
	headers: {
		'X-Forwarded-By': 'me'
	},
	cookies: {
		mySession: 'some cookie value'
	},
	auth: {
		username: 'foo',
		password: 'bar'
	},
	dataType: 'json'		
})
.then(function(response) {
	// get the response body
	response.getBody();

   	// get the response headers
 	response.getHeaders();

 	// get specific response header
 	response.getHeader('Accept');
 
 	// get the code
 	response.getCode();
});

requestify.get(url, options)

Executes a GET method request

requestify.get('http://example.com').then(function(response) {
	// Get the response body
	response.getBody();
});

requestify.post(url, data, options)

Executes a POST method request

requestify.post('http://example.com', {
		hello: 'world'
})
.then(function(response) {
	// Get the response body
	response.getBody();
});

requestify.put(url, data, options)

Executes a PUT method request

requestify.put('http://example.com', 'some-file-content').then(function(response) {
	// Get the response body
	response.getBody();
});

requestify.delete(url, options)

Executes a DELETE method request

requestify.delete('http://example.com').then(function(response) {
	// Get the response body
	response.getBody();
});

requestify.head(url, options)

Executes a HEAD method request

requestify.head('http://example.com').then(function(response) {
	// Get the response code
	response.getCode();
});

Running Tests

To run the test suite first install the development dependencies:

$ npm install	

Then run the tests:

$ npm test

License

The MIT License (MIT)

Copyright (c) 2013 Ran Mizrahi <ranm@codeoasis.com>

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.

FAQs

Package last updated on 26 Jun 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc