mini-rest

0.5.0 • Public • Published

README

Simple lib use for creating simple REST API with Node and Express

Usage

Build default service :

Service is a function to execute on call

var ServerMiniRest = require('./ServerMiniRest.js');
var server = new ServerMiniRest();
var service = function (req, res) {
  server.sendJsonResponse(res, { msg: 'default service' });
};
server.define(service);

Setting services parameters

Function define(service) can take parameters with define(service, params)

{
  host: "/", // Path of the service (default: "/")
  type: "get" // get, post, all, ... (default: "all")
  basicAuth: {username: null, password: null} // (default: "null")
}

Setting server parameters

Function start() can take parameters with start(params)

{
  port: "80", // Port of application (default: "80")
  notFoundService: service // Custom Not found service
}

Public methods

required and optional parameters


define (service, serviceParameters)

Attach service in the application


start (serverParameters)

Start the application


sendJsonResponse (response, object, HttpCode)

Send response with an JSON string in a JSON content type.


sendJsonError (response, object, HttpCode)

Send an stringify object in a JSON content type.


Testing

CLI: npm test

Junit.xml file: npm run testJunit (test/test-results.xml)

Readme

Keywords

none

Package Sidebar

Install

npm i mini-rest

Weekly Downloads

0

Version

0.5.0

License

ISC

Last publish

Collaborators

  • esenor