esi-server-data-koa-router
koa-router based data provider for esi-server
Usage
Configuration
const Router = require("koa-router"),
Provider = require("esi-server-data-koa-router"),
router = new Router(),
provider = new Provider({router:router});
router.get("/users/:id", (ctx, next) => {
if (ctx.params.id === "1") {
ctx.body = {"id": 1, "name": "John Doe", "email": "john.doe@example.com"};
} else {
next();
}
});
Fetching data
provider
.get("/users/1")
.then( user => {
console.log(user);
});
404 handling
provider
.get("/users/404")
.catch( err => {
console.log(err.message, err.status);
});