Skip to content

Commit 35cdd91

Browse files
committed
docs(event-handler): document catch-all route feature
1 parent b9fa07a commit 35cdd91

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Diff for: docs/core/event_handler/api_gateway.md

+38
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ You can use `/path/{dynamic_value}` when configuring dynamic URL paths. This all
287287
}
288288
```
289289

290+
#### Nested routes
291+
290292
You can also nest paths as configured earlier in [our sample infrastructure](#required-resources): `/{message}/{name}`.
291293

292294
=== "app.py"
@@ -323,6 +325,42 @@ You can also nest paths as configured earlier in [our sample infrastructure](#re
323325
}
324326
```
325327

328+
#### Catch-all routes
329+
330+
!!! note "We recommend having explicit routes whenever possible; use catch-all routes sparingly"
331+
332+
You can use a regex string to handle an arbitrary number of paths within a request, for example `.+`.
333+
334+
You can also combine nested paths with greedy regex to catch in between routes.
335+
336+
!!! warning "We will choose the more explicit registered route that match incoming event"
337+
338+
=== "app.py"
339+
340+
```python hl_lines="5"
341+
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
342+
343+
app = ApiGatewayResolver()
344+
345+
@app.get(".+")
346+
def catch_any_route_after_any():
347+
return {"path_received": app.current_event.path}
348+
349+
def lambda_handler(event, context):
350+
return app.resolve(event, context)
351+
```
352+
353+
=== "sample_request.json"
354+
355+
```json
356+
{
357+
"resource": "/any/route/should/work",
358+
"path": "/any/route/should/work",
359+
"httpMethod": "GET",
360+
...
361+
}
362+
```
363+
326364
### Accessing request details
327365

328366
By integrating with [Data classes utilities](../../utilities/data_classes.md){target="_blank"}, you have access to request details, Lambda context and also some convenient methods.

0 commit comments

Comments
 (0)