Update README.md

This commit is contained in:
Typicode
2015-06-16 02:23:26 +02:00
parent 34f6fd3412
commit 509f4965b2

View File

@ -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)