0.0.10 • Published 11 years ago

common-api v0.0.10

Weekly downloads
17
License
-
Repository
github
Last release
11 years ago

common-api

Node API abstraction library.

Usage

Without API Key

var MyAPI = function() {
    // api specific setup
};

MyAPI.prototype = new API({
    hostname: 'api.domain.com',
    format:   API.FORMAT.JSON,
    // prefix for all api reqeusts
    base:     '/v1'
});

MyAPI.prototype.getWidgets = function() {
    // this.call returns a promise.
    //
    // The constructed URL for this call would be:
    //     http://api.domain.com/v1/widgets
    //
    return this.call('widgets').then(function(widgets) {
        // do some transformations on the api response

        return widgets;
    };
};

With API Key in URL

var MyAPI = function(api_key) {
    // setup
    this.api_key = api_key;
};

MyAPI.prototype = new API({
    hostname: 'api.domain.com',
    // use https on port 443
    secure:   true,
    format:   API.FORMAT.JSON,
    base:     '/json/{api_key}',

    // urlTransform is called after building the request URL.
    urlTransform: function(url) { return url.replace('{api_key}', this.api_key); }
});
0.0.10

11 years ago

0.0.9

11 years ago

0.0.8

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago