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

328
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
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