0.1.8 • Published 9 years ago

http-api-client v0.1.8

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

http-api-client Build Status

An easy to use NodeJS HTTP API client library.

Installation

npm install http-api-client --save

Usage

var client = require('http-api-client');

client.request({
    url: 'http://hawttrends.appspot.com/api/terms/'
}).then(function (response) {
    response.getStatusCode(); // returns the HTTP status code
    console.log(response.getData()); // returns the string representation of the response body
    response.getBuffer(); // returns the raw response Buffer object http://nodejs.org/api/buffer.html
    response.getNativeResonse(); // returns the native NodeJS repsonse object
    response.getJSON(); // returns a JSON-parsed repsonse
});

API

client.request({
    url: 'http://example.com', // required, protocol can be HTTPS
    method: 'POST',  // optional
    encoding: 'utf8', // optional
    parameters: { param: 'value' } // optional POST parameters,
    cookies: { // optional object containing cookies
        cookieName: cookieValue
    },
    data: rawRequestBody // optional raw request body data
    files: { // optional file uploads
        fieldname: {
            name: 'filename',
            type: 'application/octet-stream',
            data:  fileDataBuffer
        }
    }
}).then(function (/* Response object */response) {
    // Success
    response.request({
        url: 'http://example.com/something'
    }); // will make a request perserving the cookies from the previous request
}, function (error) {
    // Failure
});
0.1.8

9 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago