[feat] add support for path-group style routing
sombriks opened this issue · comments
Leonardo Silveira commented
Describe the feature
i am looking for a path-building idiom using koa-router similar to what javalin does.
something like this would be nice:
const group = new Router.Group().path("/", group => {
group.post("login", loginRequest)
group.post("signup", signupRequest)
group.path("user/:userId/accounts", ifAuthenticated, group => {
group.get(listAccountsRequest)
group.post(ifAllowed, insertAccountRequest)
group.path("/:accountId", group => {
group.get(findAccountRequest)
group.put(updateAccountRequest)
group.del(ifAllowed, delAccountRequest)
group.get("/transactions",listTransactionsRequest)
})
})
})
// then we build our api definition into a router
const router = group.build()
Checklist
- I have searched through GitHub issues for similar issues.
- I have completely read through the README and documentation.
Leonardo Silveira commented
I've created a pull request implementing it but after some consideration it makes little sense to add this to the router itself; instead, a supporting library brings the very same benefit without growing the current router api surface. https://github.com/sombriks/koa-api-builder