This example demonstrates how to use koa-resource-routes
in a modular way with the new
ES6 Module Syntax. It consists of users,
events, and photos in events. This example shows how to implement the following routes:
Users:
POST /v1/users
- Create a new userGET /v1/users/:usersParam
- Return a specific user given an IDPUT /v1/users/:usersParam
- Update a specific user given an ID
Events:
GET /v1/events
- Return a list of eventsPOST /v1/events
- Create a new eventGET /v1/events/:eventsParam
- Return a specific event given an IDPUT /v1/events/:eventsParam
- Update a specific event given an IDDELETE /v1/events/:eventsParam
- Delete a specific event given an ID
Photos:
POST /v1/events/:eventsParam/photos
- Create a photo for an event
The gist of this example is to show how you can export other modules and compose various resource routes. To compose a resource within another resource, add the following line of code to an already existing resource.
export * as innerResource from './innerResource';
// All of your other routing methods for this resource can go in this file as well.
export function* index(next) {
// ...
}
export function* show(next) {
// ...
}