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 likemaxAge, 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
npm install restful-api-framework --save
Click here to see an example written in Typescript
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.