generator-express-no-stress
Version:
Awesome APIs with ExpressJS and OpenAPI/Swagger: Features automatic request validation, interactive api doc, and more.
28 lines (24 loc) • 557 B
JavaScript
import ExamplesService from '../../services/examples.service';
export class Controller {
all(req, res) {
ExamplesService.all()
.then(r => res.json(r));
}
byId(req, res) {
ExamplesService
.byId(req.params.id)
.then(r => {
if (r) res.json(r);
else res.status(404).end();
});
}
create(req, res) {
ExamplesService
.create(req.body.name)
.then(r => res
.status(201)
.location(`<%= apiRoot %>/examples/${r.id}`)
.json(r));
}
}
export default new Controller();