...
Codeblock | ||
---|---|---|
| ||
/// <reference path="../../../.vscode.js"/>
import { RouterBuilder } from '@de.pinuts.apirouter/shared/routing.es6';
const list = (req, res) => {
// Will be called when requesting GET <http://localhost:8080/cmsbs/rest/de.mycompany.restdemo.api/document>
res.json({
message: 'list has been called'
});
}
const show = (req, res) => {
// Will be called when requesting GET <http://localhost:8080/cmsbs/rest/de.mycompany.restdemo.api/document/123>
res.json({
message: 'show has been called!',
req.params
});
}
const update = (req, res) => {
// Will be called when requesting PUT <http://localhost:8080/cmsbs/rest/de.mycompany.restdemo.api/document/123>
res.json({
message: 'update has been called',
req.params
});
}
const create = (req, res) => {
// Will be called when requesting POST <http://localhost:8080/cmsbs/rest/de.mycompany.restdemo.api/document>
res.json({
message: 'create has been called',
req.params
});
}
const remove = (req, res) => {
// Will be called when requesting DELETE <http://localhost:8080/cmsbs/rest/de.mycompany.restdemo.api/document/123>
res.json({
message: 'remove has been called',
req.params
});
}
const basicAuth = (username, password) => {
const e = UM.getEntry('login_name', username);
return e && e.testPassword(password) && e.get('entrytype') == 'apiuser';
}
const routerBuilder = new RouterBuilder()
// .protectFromForgery()
.protectFromCaching()
.allowCors()
.handlePreflightRequests()
// .requireOpenPassword()
// .requireBasicAuth('api-realm', basicAuth)
// .requireApiKey() // Since UM 7.55.1
.get('/document/:id', show)
.get('/document', list)
.put('/document/:id', update)
.post('/document', create)
.delete('/document/:id', remove);
de.mycompany.restdemo.apiController = routerBuilder.build(); |
...