Add support for greedy catch-all path variables
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:
- 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".
- 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.
Hey @jamesls any chance we can get this PR merged?
Just came across this issue whilst building locally.
Any chance we can get this merged?
Bumping this. I think greedy catch-all path is still a big problem. Atleast I haven't been able to get it working.