Skip to content

Commit c8aacd2

Browse files
committed
Update README.md
1 parent cf01510 commit c8aacd2

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JSON Server [![](https://travis-ci.org/typicode/json-server.svg)](https://travis-ci.org/typicode/json-server) [![](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server) [![](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/typicode/json-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
22

3-
> Get a full fake REST API with __zero coding__ in __less than 30 seconds__ (seriously)
3+
Get a full fake REST API with __zero coding__ in __less than 30 seconds__ (seriously)
44

55
Created with :sparkling_heart: for front-end developers who need a quick back-end for prototyping and mocking.
66

@@ -129,26 +129,22 @@ $ json-server index.js
129129

130130
### Module
131131

132+
If you need to add authentication, validation, rewrite or add routes, you can use the project as a module in combination with other Express middlewares.
133+
132134
```javascript
133135
var jsonServer = require('json-server')
134136

135-
// Express server
136-
var server = jsonServer.create()
137-
138-
// Default middlewares (logger, public, cors)
139-
server.use(jsonServer.defaults)
140-
141-
// Add other Express middlewares if needed (authentication, redirections, ...)
142-
// ...
137+
var server = jsonServer.create() // Returns an Express server
138+
var router = jsonServer.router('db.json') // Returns an Express router
143139

144-
// Express router
145-
server.use(jsonServer.router('db.json'))
140+
server.use(jsonServer.defaults) // logger, static and cors middlewares
141+
server.use(router) // Mount router on '/'
146142

147143
server.listen(3000)
148144
```
149145

150146
For an in-memory database, you can pass an object to `jsonServer.route()`.
151-
Please note also that you can use the `jsonServer.router()` in existing Express servers.
147+
Please note also that `jsonServer.router()` can be used in existing Express projects.
152148

153149
### Deployment
154150

0 commit comments

Comments
 (0)