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

387
Vistas
How to define multiple paths for one handler in serverless?

I have been trying and searched online, but was not able to find a response. Is it possible to achieve the following using Serverless Framework:

I want to use the get.handler that has the code to the following definition for both getting one item and getting all the items. So:

  • if I hit api.example.com/items/ I retrieve all the items
  • if I hit api.example.com/items/1234 I retrieve item with id = 1234
 - get_items:
    handler: project/items/get.handler
    events:
      - http:
          path: items/{itemId}
          method: get

So far in the get.handler I check event.pathParameters? event.pathParameters.itemId : null if the specific item exists and call some getItem(itemdId) function and if it does not exits I call a getAll() function.

If I pass the item id in the path it works, but when I make a request for api.example.com/items/ I get the following error: not a valid key=value pair (missing equal-sign) in Authorization header. This means something is wrong in my path and I have to pass the item id to the path parameters.

My question is: Is there a way I can use multiple paths in the - http: area, or what would be a recommended way to solve this issue (just create two separate handlers) ?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There are two ways to easily accomplish what you're looking for. Firstly, a lambda function can be triggered by multiple events. You can add another http event to the array of handlers like so:

get_items:
    handler: project/items/get.handler
    events:
      - http:
          path: items/{itemId}
          method: get
      - http:
          path: items/
          method: get

Alternatively, you could use the {proxy+} argument. You can read more about the various proxy methods here

over 4 years ago · Santiago Trujillo 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