mirror of
https://github.com/typicode/json-server.git
synced 2025-07-27 20:23:34 +08:00
Update README.md
This commit is contained in:
17
README.md
17
README.md
@ -148,9 +148,7 @@ Create a `routes.json` file.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"/api/:resource": "/:resource",
|
"/api/": "/",
|
||||||
"/api/:resource/:id": "/:resource/:id",
|
|
||||||
"/api/:parent/:parentId/:resource": "/:parent/:parentId/:resource",
|
|
||||||
"/blog/posts/:id/show": "/posts/:id"
|
"/blog/posts/:id/show": "/posts/:id"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -163,9 +161,10 @@ json-server db.json --routes routes.json
|
|||||||
|
|
||||||
Now you can access resources using additional routes.
|
Now you can access resources using additional routes.
|
||||||
|
|
||||||
```
|
```bash
|
||||||
/api/posts/1 -> /posts/1
|
/api/posts # /posts/1
|
||||||
/blog/posts/1/show -> /posts/1
|
/api/posts/1 # /posts/1
|
||||||
|
/blog/posts/1/show # /posts/1
|
||||||
```
|
```
|
||||||
|
|
||||||
### Module
|
### Module
|
||||||
@ -196,12 +195,12 @@ To add rewrite rules:
|
|||||||
```javascript
|
```javascript
|
||||||
// Add this before server.use(router)
|
// Add this before server.use(router)
|
||||||
server.use(jsonServer.rewriter({
|
server.use(jsonServer.rewriter({
|
||||||
'/api/:resource': '/:resource',
|
'/api/': '/',
|
||||||
// ...
|
'/blog/posts/:id': '/posts/:id'
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
To set a global prefix:
|
Alternatively, you can also mount the router on another path.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
server.use('/api', router)
|
server.use('/api', router)
|
||||||
|
Reference in New Issue
Block a user