esi-server-data-koa-router
v1.0.1
Published
koa-router based data provider for esi-server
Downloads
1
Readme
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});
// Defining route
router.get("/users/:id", (ctx, next) => {
if (ctx.params.id === "1") {
ctx.body = {"id": 1, "name": "John Doe", "email": "[email protected]"};
} else {
next();
}
});
Fetching data
provider
.get("/users/1")
.then( user => {
console.log(user); // {"id":1,"name":"John Doe","email":"[email protected]"}
});
404 handling
provider
.get("/users/404")
.catch( err => {
console.log(err.message, err.status); // Not found 404
});