Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for greedy catch-all path variables #2012

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jacobe
Copy link

@jacobe jacobe commented Jan 4, 2023

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.

@annjawn
Copy link

annjawn commented Mar 18, 2023

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

@bt
Copy link

bt commented Apr 4, 2023

Just came across this issue whilst building locally.

Any chance we can get this merged?

@mangled-data
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants