Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit 7b8f498

Browse files
committed
Initial commit
0 parents  commit 7b8f498

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
```

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "restified",
3+
"version": "0.0.1-dev.0",
4+
"description": "REST routes constructor for express and koa",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/atomixinteractions/restified.git"
12+
},
13+
"author": "Sergey Sova <i.am@lestad.net> (https://lestad.top)",
14+
"license": "MIT",
15+
"bugs": {
16+
"url": "https://github.com/atomixinteractions/restified/issues"
17+
},
18+
"homepage": "https://github.com/atomixinteractions/restified#readme"
19+
}

0 commit comments

Comments
 (0)