an interface definition lib for koa, express...
Last updated a year ago by netssfy .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install node-contract 
SYNC missed versions from official npm registry.


a interface definition lib for koa


Use a js Object to give web api definition including url, method, description, input parameters definition and result definition. The object is called as Contract;

Then you can specifiy which Contracts to be loaded by node-contract framework.

parameter checking

When request comes, framework will check the actual parameters against defined parameters. if any problem happens, like require parameter is not found or type mismatch, framework will terminate the further process and return error.

sample contract definition

var contract = Contract({
  name: 'test api',
  url: '/test/api',
  method: 'get',
  description: 'a test api',
  params: {
    type: { TYPE: String, from: 'query', description: 'type' },
    page: { TYPE: Number, from: 'query', require: false, description: 'which page' },
    pageSize: { TYPE: Number, from: 'query', require: false, description: 'size of page ' },
    platform: { TYPE: String, from: 'body', in: ['ios', 'android'] }
  result: { TYPE: [{name: String}], description: 'result is a list of object, each contains name fields' },
  processor: getList
//this is processor function which take params and output result
function* getList(type, page, pageSize) {
  return [{
    name: 'test1'
  }, {
    name: 'test2'

the above code give a clear definition of web api. Also it restricts the params for us. type is a required String param and comes from querystring page is a optional Number param and also comes from querystring pageSize is a optional Number param and also comes from querystring

Maintainers (1)
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 3
Dependencies (3)
Dev Dependencies (6)
Dependents (0)

Copyright 2014 - 2016 © |