|
| 1 | +# Restified |
| 2 | + |
| 3 | +Declare your routes |
| 4 | + |
| 5 | + |
| 6 | +## Warning! |
| 7 | + |
| 8 | +> That middleware now in development! Do not use it in production (only before v1 release) |
| 9 | +
|
| 10 | + |
| 11 | +## Usage example |
| 12 | + |
| 13 | +```js |
| 14 | +import Restified from 'restified' |
| 15 | + |
| 16 | +import { |
| 17 | + BooksController, |
| 18 | + SectionsController, |
| 19 | + DemosController, |
| 20 | + LikeController, |
| 21 | + ProfileController, |
| 22 | + BookmarksController, |
| 23 | +} from './controllers' |
| 24 | + |
| 25 | +const router = Restified() |
| 26 | + |
| 27 | + |
| 28 | +router.root(r => { |
| 29 | + r.resources('book', {}, BooksController) |
| 30 | + // get /books -> BooksController.#index |
| 31 | + // post /books -> BooksController.#create |
| 32 | + // get /books/:bookId -> BooksController.#read |
| 33 | + // put /books/:bookId -> BooksController.#update |
| 34 | + // patch /books/:bookId -> BooksController.#update |
| 35 | + // delete /books/:bookId -> BooksController.#destroy |
| 36 | + |
| 37 | + r.resources('section', { only: ['index', 'read'] }, SectionsController) |
| 38 | + // get /sections -> SectionsController.#index |
| 39 | + // get /sections/:sectionId -> SectionsController.#read |
| 40 | + |
| 41 | + r.resources('demo', {}, DemosController, r => { |
| 42 | + r.member.post('close') |
| 43 | + r.member.post('open', { methodName: 'reopen' }) |
| 44 | + |
| 45 | + r.resource('like', LikeController) |
| 46 | + }) |
| 47 | + // get /demos -> DemosController.#index |
| 48 | + // post /demos -> DemosController.#create |
| 49 | + // get /demos/:demoId -> DemosController.#read |
| 50 | + // put /demos/:demoId -> DemosController.#update |
| 51 | + // patch /demos/:demoId -> DemosController.#update |
| 52 | + // delete /demos/:demoId -> DemosController.#destroy |
| 53 | + // post /demos/:demoId/close -> DemosController.#close |
| 54 | + // post /demos/:demoId/open -> DemosController.#reopen |
| 55 | + // get /demos/like -> LikeController.#read |
| 56 | + // post /demos/like -> LikeController.#create |
| 57 | + // put /demos/like -> LikeController.#update |
| 58 | + // delete /demos/like -> LikeController.#destroy |
| 59 | + |
| 60 | + r.resource('profile', {}, ProfileController, r => { |
| 61 | + r.resources('bookmark', { memberId: 'id' }, BookmarksController, r => { |
| 62 | + r.member({}, r => { |
| 63 | + r.resource('share_link', BookmarksController.ShareLinkController) |
| 64 | + }) |
| 65 | + }) |
| 66 | + }) |
| 67 | + // get /profile -> ProfileController.#read |
| 68 | + // post /profile -> ProfileController.#create |
| 69 | + // put /profile -> ProfileController.#update |
| 70 | + // delete /profile -> ProfileController.#destroy |
| 71 | + // get /profile/bookmarks -> BookmarksController.#index |
| 72 | + // post /profile/bookmarks -> BookmarksController.#create |
| 73 | + // get /profile/bookmarks/:id -> BookmarksController.#read |
| 74 | + // put /profile/bookmarks/:id -> BookmarksController.#update |
| 75 | + // patch /profile/bookmarks/:id -> BookmarksController.#update |
| 76 | + // delete /profile/bookmarks/:id -> BookmarksController.#destroy |
| 77 | + // get /profile/bookmarks/:id/share_link -> BookmarksController.ShareLinkController.#read |
| 78 | + // post /profile/bookmarks/:id/share_link -> BookmarksController.ShareLinkController.#create |
| 79 | + // patch /profile/bookmarks/:id/share_link -> BookmarksController.ShareLinkController.#update |
| 80 | + // delete /profile/bookmarks/:id/share_link -> BookmarksController.ShareLinkController.#destroy |
| 81 | +}) |
| 82 | + |
| 83 | +export default router.expressMiddleware() |
| 84 | + |
| 85 | +// or for Koa |
| 86 | +// export default router.koaMiddleware() |
| 87 | + |
| 88 | +``` |
0 commit comments