typescript_base_rest_api
v1.5.6
Published
[](https://coveralls.io/github/Artear/typescript-base-rest-api-dynamodb-module?branch=master) [: void {
this.get("/items", ItemService.getItems);
this.get("/items/:id", ItemService.findById);
}
}
2. Create a service
export default class ItemService extends BaseService {
static controller: ItemController = new ItemController();
@RestifyValidation.isAlphanumeric("id")
public static findById(req: Request, res: Response, next: Next): void {
// do stuff
}
public static getItems(req: Request, res: Response, next: Next): void {
// do other stuff
}
3. Configure your server
let options: ServerOptions = new OptionsBuilder()
.withName(config.get<string>("server.options.name"))
.withVersion(config.get<string>("server.options.version"))
.build();
export let server: Server = new ServerBuilder()
.withTimeout(config.get<number>("server.options.timeout"))
.withOptions(options)
.withQueryParser(queryParser())
.withRouter(new PingRouter())
.withRouter(new ItemRouter())
.withCORS(false)
.build();
let port = config.get<number>("port");
server.listen(port, function () {
loggerHelper.info("App online on port: " + port);
});
4. Run your application!
The API will be running at http://localhost:8282
Configure your application
You can configure your application using environment variables. Example:
{
"port": "PORT",
"security": {
"enable": "SECURITY_ENABLE",
"token": "SECURITY_TOKEN"
},
"newrelic": {
"enable": "NEWRELIC_ENABLE",
"license_key": "NEWRELIC_LICENSE_KEY",
"app_name": "NEWRELIC_APP_NAME"
}
}
Examples
Check examples folder to see some basic usage.
Development
To use lint in development, you need to install typescript and tslist globally:
npm install -g typescript tslint