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

325
Vistas
Not able to use query param with expressJs api in localhost

In my index.js file

app.use('/api/v1/users', userRouter)

In Router file

router.get("/:id", getUserDataById);

In postman:

My GET URL looks like this: http://localhost:3000/api/v1/users?id=120622

Error it gives:

Cannot GET /api/v1/users

I think, this is how query param should be given according to the docs and tutorials i followed, but this error won't go away.

If i remove query, then other endpoints work perfectly.

I am not able to catch what's going wrong here.

I am stuck with this from last 2 days. Just a hint to resolve this, will help me a lot.

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Firstly your index.js and routes.js file is fine now you just need to send request correctly see the req.params is different and the req.query is different

First Way with (Query)

In postman:

http://localhost:3000/api/v1/users?id=120622

Your Index.

app.use('/api/v1/users', userRouter);

In Router file.

router.get("/", getUserDataById);

How did you get that id;

let id = req.query.id;

Second Way with (Params) - Look at the postman URL carefully and at Route

In postman:

http://localhost:3000/api/v1/users/120622

Your Index.

app.use('/api/v1/users', userRouter);

In Router file.

router.get("/:id", getUserDataById);

How did you get that id;

let id = req.params.id;

This is the two-way you can get your id, Let me know if you have any more questions and I'll try to clarify your points with more clarity.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are not calling API correctly inside the Postman. You should call it like this:

http://localhost:3000/api/v1/users/120622
about 4 years ago · Juan Pablo Isaza Denunciar

0

In the router file, what you are using is Route Parameter where the valid URL would be http://localhost:3000/api/v1/users/120622. for your Postman api to work you should remove :id at router file

about 4 years ago · Juan Pablo Isaza Denunciar
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