Skip to content

Commit

Permalink
docs(event-handler): document catch-all routes (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
heitorlessa committed Sep 28, 2021
1 parent cec2f01 commit 977162a
Showing 1 changed file with 38 additions and 0 deletions.
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

0 comments on commit 977162a

Please sign in to comment.