2.0.2 • Published 7 years ago

restful-api-framework v2.0.2

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

RESTful API framework

Lightweight framework for building RESTful APIs in NodeJS

Configuration variables

  • name string Currently not in use
  • serverName string 'server' header value
  • enableSecurityHeaders boolean, Default: true
  • port number API server port
  • cors object Object where you can set the cors information like maxAge, origin, credentials

Route

  • method string Request method
  • path string Path name, variables in path should start with colon : (ex. /path/:id)
  • middleware function Single middleware function or array of a middleware functions
  • service function Route controller

Installing the framework

npm install restful-api-framework --save

Example

Click here to see an example written in Typescript


Built in errors

API framework has a few built in errors what you can use as a response.

import { Request, Response, Errors } from 'restful-api-framework';

function MyService(request: Request, response: Response) {
    response.send(new Errors.InternalError); // status code 500, internal error
}
  • new Errors.InvalidCredentialsError - Status code 301, Invalid Credentials
  • new Errors.NotAuthorizedError - Status code 403, Not authorized
  • new Errors.ResourceNotFoundError - Status code 404, Not found
  • new Errors.MissingParameterError - Status code 409, Missing parameter error
  • new Errors.InternalError - Status code 500, Internal error

Feel free to submit issues and requests.

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago