Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
How to map the id parameter of the json-server onto a custom name

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?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda