2.0.2 • Published 9 years ago
restful-api-framework v2.0.2
RESTful API framework
Lightweight framework for building RESTful APIs in NodeJS
Configuration variables
namestring Currently not in useserverNamestring 'server' header valueenableSecurityHeadersboolean, Default: trueportnumber API server portcorsobject Object where you can set the cors information likemaxAge, origin, credentials
Route
methodstring Request methodpathstring Path name, variables in path should start with colon :(ex. /path/:id)middlewarefunction Single middleware function or array of a middleware functionsservicefunction 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.