shallker-wang / my-http

My Node http interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

my-http

My Node http interface.

Build Status

Installation

Use npm:

npm install git://github.com/shallker-wang/my-http.git

Or add to your package dependencies:

{
  "dependencies": {
    "my-http": "git://github.com/shallker-wang/my-http.git"
  }
}

Quick Start

Require and create an instance of MyHttp:

var MyHttp = require('my-http');
var http = new MyHttp();
var data = JSON.stringify({name: 'Curry Chicken'});
http.set('url', 'http://site.com/api/food/');
http.set('method', 'POST');
http.set('data', data);
http.setHeader('Content-Type', 'application/json;charset=utf-8');
http.setHeader('Content-Length', data.length);
http.on('error', function(err) {
  console.log('Handling error');
});
http.on('complete', onComplete);
http.request(onComplete);
function onComplete(result, res) {
  console.log('Done');
}

APIs

Set URL:

http.set('url', 'http://site.com/api/user');

Set method:

http.set('method', 'POST');

Set data:

http.set('data', 'Hello, World!');

Set a header:

http.setHeader('Content-Type', 'application/json');

Set event listeners:

http.on('error', function(err) {})
http.on('response', function(res) {})
http.on('complete', function(data) {})

Make a request:

http.request();

Todo

  • write a test

About

My Node http interface.


Languages

Language:JavaScript 100.0%