restful-api-framework
v2.0.2
Published
NodeJS framework for building RESTful APIs
Downloads
9
Readme
RESTful API framework
Lightweight framework for building RESTful APIs in NodeJS
Configuration variables
name[string] Currently not in useserverName[string] 'server' header valueenableSecurityHeaders[boolean], Default: trueport[number] API server portcors[object] Object where you can set the cors information likemaxAge, origin, credentials
Route
method[string] Request methodpath[string] Path name, variables in path should start with colon :(ex. /path/:id)middleware[function] Single middleware function or array of a middleware functionsservice[function] Route controller
Installing the framework
npm install restful-api-framework --saveExample
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 Credentialsnew Errors.NotAuthorizedError- Status code 403, Not authorizednew Errors.ResourceNotFoundError- Status code 404, Not foundnew Errors.MissingParameterError- Status code 409, Missing parameter errornew Errors.InternalError- Status code 500, Internal error
Feel free to submit issues and requests.
