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

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

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