npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

http-ext

v0.4.5

Published

the http request client for nodejs module

Downloads

11

Readme

http-ext

NPM version Build Status Dependency Status Coverage Status

the http request client for nodejs module

Install

You can install http-ext using the Node Package Manager (npm):

$ npm install --save http-ext

Simple Usage

var httpExt = require('http-ext');

httpExt.get('http://www.google.com', function (err, res){
  if (err) return console.log(err);
  console.log(res.body);
});

How to use


Arguments

  • url: The url to connect to. Can be http or https.
  • options: (all are optional) The following options can be passed:
    • parameters: an object of query parameters
    • headers: an object of headers
    • cookies: an array of cookies
    • allowRedirects: (default: true , only with httpExt.get() ), if true, redirects will be followed
    • maxRedirects: (default: 10 ). For example 1 redirect will allow for one normal request and 1 extra redirected request.
    • timeout: (default: none ). Adds a timeout to the http(s) request. Should be in milliseconds.
    • proxy, if you want to pass your request through a http(s) proxy server:
      • host: eg: "192.168.0.1"
      • port: eg: 8888
      • protocol: (default: 'http' ) can be 'http' or 'https'
    • rejectUnauthorized: validate certificate for request with HTTPS. More here
  • callback(err, res): A callback function which is called when the request is complete. res contains and response ( res ) the body ( res.body )

Example without options

var httpExt = require('http-ext');

httpExt.get('http://www.google.com', function (err, res){
	if (err) return console.log(err);
	console.log(res.body);
});

Example with options

var httpExt = require('http-ext');

httpExt.get('http://posttestserver.com/post.php', {
	parameters: {
		name: 'John',
		lastname: 'Doe'
	},
	headers:{
		'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:18.0) Gecko/20100101 Firefox/18.0'
	},
	cookies: [
		'token=DGcGUmplWQSjfqEvmu%2BZA%2Fc',
		'id=2'
	]
}, function (err, res){
	if (err){
		console.log(err);
	}else{
		console.log(res.body);
	}
});

Arguments

  • url: The url to connect to. Can be http or https.
  • options: (all are optional) The following options can be passed:
    • parameters: an object of post parameters (content-type is set to application/x-www-form-urlencoded; charset=UTF-8)
    • json: if you want to send json directly (content-type is set to application/json)
    • body: custom body content you want to send. If used, previous options will be ignored and your custom body will be sent. (content-type will not be set)
    • headers: an object of headers
    • cookies: an array of cookies
    • allowRedirects: (default: false ), if true, redirects will be followed
    • maxRedirects: (default: 10 ). For example 1 redirect will allow for one normal request and 1 extra redirected request.
    • timeout: (default: none). Adds a timeout to the http(s) request. Should be in milliseconds.
    • proxy, if you want to pass your request through a http(s) proxy server:
      • host: eg: "192.168.0.1"
      • port: eg: 8888
      • protocol: (default: 'http' ) can be 'http' or 'https'
    • rejectUnauthorized: validate certificate for request with HTTPS. More here
  • callback(err, res): A callback function which is called when the request is complete. res contains the response ( res ) and the body ( res.body )

Example without extra options

var httpExt = require('httpExt');

httpExt.post('http://posttestserver.com/post.php', {
	parameters: {
		name: 'John',
		lastname: 'Doe'
	}
}, function (err, res){
	if (err){
		console.log(err);
	}else{
		console.log(res.body);
	}
});

Example with options

var httpExt = require('http-ext');

httpExt.post('http://posttestserver.com/post.php', {
	parameters: {
		name: 'John',
		lastname: 'Doe'
	},
	headers:{
		'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:18.0) Gecko/20100101 Firefox/18.0'
	},
	cookies: [
		'token=DGcGUmplWQSjfqEvmu%2BZA%2Fc',
		'id=2'
	]
}, function (err, res){
	if (err){
		console.log(err);
	}else{
		console.log(res.body);
	}
});

Same options as httpExt.post(url, [options], callback)


Same options as httpExt.post(url, [options], callback)


Example

var httpExt = require('http-ext');

httpExt.post('http://posttestserver.com/post.php',{
  body: '<?xml version="1.0" encoding="UTF-8"?>',
  headers: {
    'Content-Type': 'text/xml',
  }},
  function (err, res) {
    if (err){
      console.log(err);
    } else {
      console.log(res.body);
    }
  }
);

Example

var httpExt = require('http-ext');

httpExt.post('http://posttestserver.com/post.php', {
  proxy: {
    host: 'localhost',
    port: 8888
  }
}, function (err, res){
  if (err){
    console.log(err);
  }else{
    console.log(res.body);
  }
});

API

(Coming soon)

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using gulp.

License

Copyright (c) 2015 liuxiong. Licensed under the MIT license.