restful-api-framework
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i restful-api-framework

Weekly Downloads

4

Version

2.0.2

License

MIT

Last publish

Collaborators

  • kozjat