-
Notifications
You must be signed in to change notification settings - Fork 1
HTTP – Routes
Bartosz Łaniewski edited this page Mar 24, 2018
·
8 revisions
A router is a class which defines a group of routes under a common namespace. Our framework automatically initialises and populates each imported router. Additionally, we provide several decorators for faster RESTful APIs creation and middleware handling.
import compose from "koa-compose";
import {get, post, patch, del} from "inra-server-http";
class SomeRouter {
constructor({models, logger, middlewares}) {
this.models = models;
this.logger = logger;
}
@post("/some/route", function() {
return compose([
// `this` is bound to imported middlewares
this.middlewareA(),
this.middlewareB()
]);
})
create(ctx, next) {
// …
}
@get("/some/route/:id")
read(ctx, next) {
// …
}
@patch("/some/route/:id")
update(ctx, next) {
// …
}
@del("/some/route/:id")
delete(ctx, next) {
// …
}
}
This Wiki and indvidual modules READMEs contains a lot of information – please take your time and read these instructions carefully.