api2go
Simple structure to create APIs based on HTTP requests over express.
Last updated 3 years ago by quagliato .
MIT License · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install api2go 
SYNC missed versions from official npm registry.

API2go

Build Status

Description

Simple structure to create APIs based on HTTP requests over express.

You can create RESTful or RPC APIs, using any kind of HTTP method accepted by expressjs and customize the paths you use.

Why use API2Go instead of express?

API2Go abstracts a lot of things that in express you would have to implement manually, like this:

  • Logger: API2GO() has a logger function publicly accessible;
  • Email: every instance of API2Go() has also a function sendMail publicly accessible;
  • Auditing: the API2Go logs every request, the input, the output, how many time it tooks to process etc.

Some things that need to be implemented

Like any one-man-army, I can't do everything at the same time, so these are some of the things that I plan to program or want to program:

  • Middleware;
  • Unified and strong authentication (can't continue using the payload);
  • Headers filtering;
  • N-level validation on functions' map;
  • Got any idea? eduardo@quagliato.me or add a new issue in the Github repo;

Usage

npm install api2go

To use (from v0.0.13 and on):

var API2Go = require('api2go');

// You can instance N API objects in the same application, but they have to
// listen to different ports.
var apiObj = new API2Go("path/to/config.json");

// You can also instance a API object without a file, but informing the config
// object right here, like this:
var apiObj = new API2Go({
  "DEBUG_MODE"               : 1,
  "NODEJS_LISTEN_PORT"       : 3000,
  "API_FUNCTIONS_MAP"        : "_assets/functions-map.json",
  "GENERAL_LOG"              : "_logs/general.log"
});

// You have to register the functions that you want to make invokable
apiObj.registerFunction("test", function(payload, requestKey, callback, req, res){
  console.log(payload);
  var returnValues = {
    "status": "OK",
    "data": data
  };

  callback(returnValues);
},
// This is the map for the function, it defines the path which this request can
// be invoke and the parameters that will be validated.
{
  "path": ":id",
  "module": "default",
  "method": "get",
  "params": [
    {
      "paramName": "parameter1",
      "type": "string",
      "mandatory": false,
      "validation": {
        "longerThan": "5",
        "smallerThan": "100"
      }
    },
    {
      "paramName": "parameter2",
      "type": "string",
      "mandatory": false,
      "validation": {
        "longerThan": "60",
        "smallerThan": "65"
      }
    }
  ]
});

// The API will start listen in the port you specified in the config.
apiObj.start();

Every request must return a property "status" with "OK" or "ERROR".

Changelog

Refer to changelog.txt inside the repo.

Keep in touch

Eduardo Quagliato, eduardo@quagliato.me

License

This project is copyrighted by MIT License (see license.txt).

Current Tags

  • 0.0.28                                ...           latest (3 years ago)

28 Versions

  • 0.0.28                                ...           3 years ago
  • 0.0.27                                ...           3 years ago
  • 0.0.26                                ...           3 years ago
  • 0.0.25                                ...           3 years ago
  • 0.0.24                                ...           4 years ago
  • 0.0.23                                ...           4 years ago
  • 0.0.22                                ...           4 years ago
  • 0.0.21                                ...           4 years ago
  • 0.0.20                                ...           4 years ago
  • 0.0.19                                ...           4 years ago
  • 0.0.18                                ...           4 years ago
  • 0.0.17                                ...           4 years ago
  • 0.0.16                                ...           4 years ago
  • 0.0.15                                ...           4 years ago
  • 0.0.14                                ...           4 years ago
  • 0.0.13                                ...           4 years ago
  • 0.0.12                                ...           4 years ago
  • 0.0.11                                ...           4 years ago
  • 0.0.10                                ...           4 years ago
  • 0.0.9                                ...           4 years ago
  • 0.0.8                                ...           4 years ago
  • 0.0.7                                ...           4 years ago
  • 0.0.6                                ...           4 years ago
  • 0.0.5                                ...           4 years ago
  • 0.0.4                                ...           4 years ago
  • 0.0.3                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (9)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |