lib-http-api

0.0.2 • Public • Published

lib-http-api

Build Status

install

npm install --save lib-http-api

usage

define an interface

var search = {
  method : 'GET',
  route  : '/search/:query',
  options: {
    limit: 100,
    order: 'asc'
  }
};

create the api

var API = require('lib-http-api')();
var api = API.New();
 
api.add('search', search);

create the client request

api.request('search', {query: 'spicy+noodles'}, {order: 'desc'});
// { path   : '/search/spicy+noodles?order=desc&limit=100',
//   method : 'GET',
//   host   : 'localhost',
//   port   : 100 }

switch off a server request

api.handle('GET', '/search/spicy+noodles?order=desc&limit=100');
// { handle: 'search',
//   params: { query: 'spicy+noodles' },
//   query: { order: 'desc', limit: '100' } }

You'll want to associate the tokens returned with route handlers.

see also

Readme

Keywords

none

Package Sidebar

Install

npm i lib-http-api

Weekly Downloads

1

Version

0.0.2

License

ISC

Last publish

Collaborators

  • groundwater