0.3.0 • Published 9 years ago

nquest v0.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

nquest

Build Status Join the chat at https://gitter.im/wangchi/nquest

Node http request helper for get, post, put and delete.

Methods

nquest(opts, callback)

The argument opts example:

{
  method: 'GET', // default
  url: 'http://localhost/test',
  data: {
    "test": "hello"
  }
}

nquest.get(url, data, callback)

Simple to use nquest when method is equal to GET.

nquest.post(url, data, callback)

Simple to use nquest when method is equal to POST.

nquest.put(url, data, callback)

Simple to use nquest when method is equal to PUT.

Install

You should install Node.js first, then install nquest.

npm install nquest --save

Use and Examples

nquest(options, callback)

The default method, you can use like nquest({...}).

var nquest = require('nquest');

var testConfig1 = {
  url: 'http://127.0.0.1:3000/nquestGetTest',
  data: {
    username: 'abc',
    age: 18
  }
};

var testConfig2 = {
  method: 'POST',
  url: 'http://127.0.0.1:3000/nquestPostTest',
  data: {
    username: 'cde',
    age: 18
  }
};

nquest(testConfig1, function (res) {
  console.log('get');
  console.log( JSON.parse(res) );
});

nquest(testConfig2, function (res) {
  console.log('post');
  console.log( JSON.parse(res) );
});

nquest.get( url, data, callback )

Like jQuery $.get() method.

var nquest = require('nquest');

nquest.get('http://127.0.0.1:3000/nquestGetTest', {
  username: 'abc',
  age: 18
}, function (res) {
  console.log( JSON.parse(res) );
});

nquest.post( url, data, callback )

var nquest = require('nquest');

nquest.post('http://127.0.0.1:3000/nquestPostTest', {
  username: 'abc',
  age: 17
}, function (res) {
  console.log( JSON.parse(res) );
});

nquest.put( url, data, callback )

var nquest = require('nquest');

nquest.put('http://127.0.0.1:3000/nquestPostTest', {
  username: 'abc',
  age: 17
}, function (res) {
  console.log( JSON.parse(res) );
});

Set headers

Your settings will overwrite the defaults.

Example:

nquest({
  method: 'POST',
  url: 'http://localhost/test',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  data: {
    "test": "hello"
  }
}, function (res) {
  console.log(res);
});

MIT License

0.3.0

9 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago