Need private packages and team management tools?Check out npm Teams »

http-ext

0.4.5 • Public • Published

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


### httpExt.get(url, [options], callback)

Arguments

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);
    }
});

### httpExt.post(url, [options], callback)

Arguments

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);
    }
});

### httpExt.put(url, [options], callback)

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


### httpExt.delete(url, [options], callback)

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


### Sending a custom body Use the body option to send a custom body (eg. an xml post)

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);
    }
  }
);

### Using a http(s) proxy

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.

Keywords

Install

npm i http-ext

DownloadsWeekly Downloads

1

Version

0.4.5

License

MIT

Last publish

Collaborators

  • avatar