포스트맨
const jsonServer = require('json-server')
const server = jsonServer.create()
const path = require('path')
const router = jsonServer.router(path.join(__dirname, 'db.json'))
const middlewares = jsonServer.defaults()
// Set default middlewares (logger, static, cors and no-cache)
server.use(middlewares)
// To handle POST, PUT and PATCH you need to use a body-parser
// You can use the one used by JSON Server
server.use(jsonServer.bodyParser)
server.use(router)
let port = 80;
server.listen(port, () => {
console.log(`JSON Server is running, port(${port})`)
})
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
node server.js
method path
전체목록조회 get /posts
추가 post /posts
삭제 delete /posts/:id
수정 put /posts/:id
출처 : https://min9nim.github.io/2018/10/json-server/
https://www.npmjs.com/package/json-server