chalice icon indicating copy to clipboard operation
chalice copied to clipboard

Add support for greedy catch-all path variables

Open jacobe opened this issue 3 years ago • 3 comments

This was attempted/discussed in #140, but here is a more complete and also tested implementation.

API Gateway has support for "greedy" path parameters in API routes, but that is not fully supported in Chalice. We have run into several use cases for such a feature in our company:

  • Varying callback URLs from 3rd parties that all need to go to one handler
  • Static asset mapping

Currently, if you specify a {proxy+} path variable in an @app.route, it will actually work, but there are a few things lacking:

  1. It's not possible to map the value to an actual parameter in the function. I'd expect to be able to get the proxied portion of the path through a parameter named "proxy".
  2. The catch-all parameter does not work for local development (chalice local)

Those gaps are implemented in this PR. Usage would be as follows:

@app.route('/foo/{proxy+}', methods=['GET'])
def example(proxy):
    return proxy

This will match any url under /foo (although not /foo itself), returning the proxied portion of the path:

GET /foo/test
=> test

GET /foo/test/bar
=> test/bar

The PR also adds support local development (chalice local) so that the matching also works locally just as it does in API Gateway.

jacobe avatar Jan 04 '23 13:01 jacobe

Hey @jamesls any chance we can get this PR merged?

annjawn avatar Mar 18 '23 04:03 annjawn

Just came across this issue whilst building locally.

Any chance we can get this merged?

bt avatar Apr 04 '23 09:04 bt

Bumping this. I think greedy catch-all path is still a big problem. Atleast I haven't been able to get it working.

mangled-data avatar Sep 09 '23 22:09 mangled-data