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

186
Visualizações
Getting input from URL using node.js

I was given the following task:

define the route

GET /api/restaurants

This route must accept the numeric query parameters "page" and "perPage" as well as the string parameter "borough", ie: /api/restaurants?page=1&perPage=5&borough=Bronx. It will use these values to return all "Restaurant" objects for a specific "page" to the client as well as optionally filtering by "borough", if provided.

my code is as follows

app.get('/api/restaurants/:page/:perPage/:borough', (req, res) =>{
  console.log("worked")
  console.log(req.params.page)
  console.log(req.params.perPage)
  console.log(req.params.borough) 
})

now here is the issue i m encountering, the route works fine if i enter the url in the following format

http://localhost:8000/api/restaurants/1/5/Bronx

however it doesn't work when using the format the instructor requires

http://localhost:8000/api/restaurants?page=1&perPage=5&borough=Bronx

I get "Cannot GET /api/restaurants", if anyone could please shed some light on what i m doing wrong i would appreciate it.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think you're confusing route parameters and query parameters. (They are not the same.)

You can access query parameters on req.query:

app.get('/api/restaurants', (req, res) => {
  console.log(req.query.page);
  console.log(req.query.perPage);
  console.log(req.query.borough);
});
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