Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda