Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/core/event_handler/api_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ You can use `/path/{dynamic_value}` when configuring dynamic URL paths. This all
}
```

#### Nested routes

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

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

#### Catch-all routes

!!! note "We recommend having explicit routes whenever possible; use catch-all routes sparingly"

You can use a regex string to handle an arbitrary number of paths within a request, for example `.+`.

You can also combine nested paths with greedy regex to catch in between routes.

!!! warning "We will choose the more explicit registered route that match incoming event"

=== "app.py"

```python hl_lines="5"
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver

app = ApiGatewayResolver()

@app.get(".+")
def catch_any_route_after_any():
return {"path_received": app.current_event.path}

def lambda_handler(event, context):
return app.resolve(event, context)
```

=== "sample_request.json"

```json
{
"resource": "/any/route/should/work",
"path": "/any/route/should/work",
"httpMethod": "GET",
...
}
```

### Accessing request details

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.
Expand Down