Giter Club home page Giter Club logo

api2go's Introduction

API2go

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? [email protected] 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, [email protected]

License

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

api2go's People

Contributors

jonhester avatar thierrydelbart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.