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

195
Vistas
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 Respuestas
Responde la pregunta

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 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