RESTful Paths with AWS

I want two routes
/admin/deals
/admin/deals/{dealId}

Where a request to “/admin/deals” returns all deals and “/admin/deals/1” returns a specific deal. Pretty standard RESTful paths.

I’ve tried

  adminGetDeal:
    handler: path
    events:
      - http:
          path: admin/deals/{dealId}
          method: get
          request:
            parameters:
              paths:
                dealId: false

And the only thing that would respond with this configuration was things in the format of “/admin/deals/foo” I never got a response from either “/admin/deals” or “/admin/deals/”.

I was able to get this working by declaring two routes, but that a LOT of extra code to make this work. Curious if there is a better way to do this?

We are currently using version 1.11.x

Assuming you’re using one handler for both /admin/deals and /admin/deals/{dealId} then this should work:

adminGetDeal:
    handler: path
    events:
      - http:
          path: admin/deals
          method: get
      - http:
          path: admin/deals/{dealId}
          method: get

You need to configure both paths as separate events that trigger the function. There is no syntax to indicate an optional parameter or default value.

2 Likes

Thanks, I will give that a try.