2

I am using the npm module json-server to simulate a simple REST-interface. As I am planning to customize its functionality a little bit, I am starting an express server and define the json-server as a middleware.

The json-server reads its response objects from a JSON file. I would like to request a specific object from this JSON file and, therefore, define the id-key as my pathvariable.

This is what I have tried so far:

const jsonServer = require('json-server')
const server = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()

server.use(middlewares)

server.get('students/:myId', (req, res) => {
    res.jsonp(req.query)
  })

Well, it doesn't work. I want to map the :myId pathvariable onto :id, since the json-server can handle the later. Is there a way to achieve this?

Luk
  • 1,009
  • 2
  • 15
  • 33

0 Answers0