Skip to content

Commit 57f7ce2

Browse files
committed
docs(metrics): snippets split, improved, and lint
1 parent 4146b74 commit 57f7ce2

9 files changed

+115
-110
lines changed

docs/core/event_handler/api_gateway.md

+31-31
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ Here's an example on how we can handle the `/todos` path.
4848
???+ info
4949
We automatically serialize `Dict` responses as JSON, trim whitespace for compact responses, and set content-type to `application/json`.
5050

51-
=== "app.py"
51+
=== "getting_started_rest_api_resolver.py"
5252

5353
```python hl_lines="5 11 14 28"
5454
--8<-- "examples/event_handler_rest/src/getting_started_rest_api_resolver.py"
5555
```
5656

57-
=== "Request"
57+
=== "getting_started_rest_api_resolver.json"
5858

5959
This utility uses `path` and `httpMethod` to route to the right function. This helps make unit tests and local invocation easier too.
6060

6161
```json hl_lines="4-5"
6262
--8<-- "examples/event_handler_rest/src/getting_started_rest_api_resolver.json"
6363
```
6464

65-
=== "Response"
65+
=== "getting_started_rest_api_resolver_output.json"
6666

6767
```json
6868
--8<-- "examples/event_handler_rest/src/getting_started_rest_api_resolver_output.json"
@@ -96,13 +96,13 @@ Each dynamic route you set must be part of your function signature. This allows
9696
???+ note
9797
For brevity, we will only include the necessary keys for each sample request for the example to work.
9898

99-
=== "app.py"
99+
=== "dynamic_routes.py"
100100

101101
```python hl_lines="14 16"
102102
--8<-- "examples/event_handler_rest/src/dynamic_routes.py"
103103
```
104104

105-
=== "Request"
105+
=== "dynamic_routes.json"
106106

107107
```json
108108
--8<-- "examples/event_handler_rest/src/dynamic_routes.json"
@@ -123,13 +123,13 @@ You can also combine nested paths with greedy regex to catch in between routes.
123123
???+ warning
124124
We choose the most explicit registered route that matches an incoming event.
125125

126-
=== "app.py"
126+
=== "dynamic_routes_catch_all.py"
127127

128128
```python hl_lines="11"
129129
--8<-- "examples/event_handler_rest/src/dynamic_routes_catch_all.py"
130130
```
131131

132-
=== "Request"
132+
=== "dynamic_routes_catch_all.json"
133133

134134
```json
135135
--8<-- "examples/event_handler_rest/src/dynamic_routes_catch_all.json"
@@ -139,13 +139,13 @@ You can also combine nested paths with greedy regex to catch in between routes.
139139

140140
You can use named decorators to specify the HTTP method that should be handled in your functions. That is, `app.<http_method>`, where the HTTP method could be `get`, `post`, `put`, `patch`, `delete`, and `options`.
141141

142-
=== "app.py"
142+
=== "http_methods.py"
143143

144144
```python hl_lines="14 17"
145145
--8<-- "examples/event_handler_rest/src/http_methods.py"
146146
```
147147

148-
=== "Request"
148+
=== "http_methods.json"
149149

150150
```json
151151
--8<-- "examples/event_handler_rest/src/http_methods.json"
@@ -225,13 +225,13 @@ When using [Custom Domain API Mappings feature](https://docs.aws.amazon.com/apig
225225

226226
To address this API Gateway behavior, we use `strip_prefixes` parameter to account for these prefixes that are now injected into the path regardless of which type of API Gateway you're using.
227227

228-
=== "app.py"
228+
=== "custom_api_mapping.py"
229229

230230
```python hl_lines="8"
231231
--8<-- "examples/event_handler_rest/src/custom_api_mapping.py"
232232
```
233233

234-
=== "Request"
234+
=== "custom_api_mapping.json"
235235

236236
```json
237237
--8<-- "examples/event_handler_rest/src/custom_api_mapping.json"
@@ -253,13 +253,13 @@ This will ensure that CORS headers are always returned as part of the response w
253253
???+ tip
254254
Optionally disable CORS on a per path basis with `cors=False` parameter.
255255

256-
=== "app.py"
256+
=== "setting_cors.py"
257257

258258
```python hl_lines="5 11-12 34"
259259
--8<-- "examples/event_handler_rest/src/setting_cors.py"
260260
```
261261

262-
=== "Response"
262+
=== "setting_cors_output.json"
263263

264264
```json
265265
--8<-- "examples/event_handler_rest/src/setting_cors_output.json"
@@ -290,13 +290,13 @@ For convenience, these are the default values when using `CORSConfig` to enable
290290

291291
You can use the `Response` class to have full control over the response, for example you might want to add additional headers or set a custom Content-type.
292292

293-
=== "app.py"
293+
=== "fine_grained_responses.py"
294294

295295
```python hl_lines="7 24-28"
296296
--8<-- "examples/event_handler_rest/src/fine_grained_responses.py"
297297
```
298298

299-
=== "Response"
299+
=== "fine_grained_responses_output.json"
300300

301301
```json
302302
--8<-- "examples/event_handler_rest/src/fine_grained_responses_output.json"
@@ -309,19 +309,19 @@ You can compress with gzip and base64 encode your responses via `compress` param
309309
???+ warning
310310
The client must send the `Accept-Encoding` header, otherwise a normal response will be sent.
311311

312-
=== "app.py"
312+
=== "compressing_responses.py"
313313

314314
```python hl_lines="14"
315315
--8<-- "examples/event_handler_rest/src/compressing_responses.py"
316316
```
317317

318-
=== "Request"
318+
=== "compressing_responses.json"
319319

320320
```json
321321
--8<-- "examples/event_handler_rest/src/compressing_responses.json"
322322
```
323323

324-
=== "Response"
324+
=== "compressing_responses_output.json"
325325

326326
```json
327327
--8<-- "examples/event_handler_rest/src/compressing_responses_output.json"
@@ -336,25 +336,25 @@ Like `compress` feature, the client must send the `Accept` header with the corre
336336
???+ warning
337337
This feature requires API Gateway to configure binary media types, see [our sample infrastructure](#required-resources) for reference.
338338

339-
=== "app.py"
339+
=== "binary_responses.py"
340340

341341
```python hl_lines="14 20"
342342
--8<-- "examples/event_handler_rest/src/binary_responses.py"
343343
```
344344

345-
=== "logo.svg"
345+
=== "binary_responses_logo.svg"
346346

347347
```xml
348348
--8<-- "examples/event_handler_rest/src/binary_responses_logo.svg"
349349
```
350350

351-
=== "Request"
351+
=== "binary_responses.json"
352352

353353
```json
354354
--8<-- "examples/event_handler_rest/src/binary_responses.json"
355355
```
356356

357-
=== "Response"
357+
=== "binary_responses_output.json"
358358

359359
```json
360360
--8<-- "examples/event_handler_rest/src/binary_responses_output.json"
@@ -387,17 +387,17 @@ You can instruct API Gateway handler to use a custom serializer to best suit you
387387

388388
As you grow the number of routes a given Lambda function should handle, it is natural to split routes into separate files to ease maintenance - That's where the `Router` feature is useful.
389389

390-
Let's assume you have `app.py` as your Lambda function entrypoint and routes in `todos.py`, this is how you'd use the `Router` feature.
390+
Let's assume you have `app.py` as your Lambda function entrypoint and routes in `split_route_module.py`, this is how you'd use the `Router` feature.
391391

392-
=== "todos.py"
392+
=== "split_route_module.py"
393393

394394
We import **Router** instead of **APIGatewayRestResolver**; syntax wise is exactly the same.
395395

396396
```python hl_lines="5 13 16 25 28"
397397
--8<-- "examples/event_handler_rest/src/split_route_module.py"
398398
```
399399

400-
=== "app.py"
400+
=== "split_route.py"
401401

402402
We use `include_router` method and include all user routers registered in the `router` global object.
403403

@@ -407,17 +407,17 @@ Let's assume you have `app.py` as your Lambda function entrypoint and routes in
407407

408408
#### Route prefix
409409

410-
In the previous example, `todos.py` routes had a `/todos` prefix. This might grow over time and become repetitive.
410+
In the previous example, `split_route_module.py` routes had a `/todos` prefix. This might grow over time and become repetitive.
411411

412-
When necessary, you can set a prefix when including a router object. This means you could remove `/todos` prefix in `todos.py` altogether.
412+
When necessary, you can set a prefix when including a router object. This means you could remove `/todos` prefix altogether.
413413

414-
=== "app.py"
414+
=== "split_route_prefix.py"
415415

416416
```python hl_lines="12"
417417
--8<-- "examples/event_handler_rest/src/split_route_prefix.py"
418418
```
419419

420-
=== "todos.py"
420+
=== "split_route_prefix_module.py"
421421

422422
```python hl_lines="13 25"
423423
--8<-- "examples/event_handler_rest/src/split_route_prefix_module.py"
@@ -509,13 +509,13 @@ your development, building, deployment tooling need to accommodate the distinct
509509

510510
You can test your routes by passing a proxy event request where `path` and `httpMethod`.
511511

512-
=== "test_app.py"
512+
=== "assert_http_response.py"
513513

514514
```python hl_lines="21-24"
515515
--8<-- "examples/event_handler_rest/src/assert_http_response.py"
516516
```
517517

518-
=== "app.py"
518+
=== "assert_http_response_module.py"
519519

520520
```python
521521
--8<-- "examples/event_handler_rest/src/assert_http_response_module.py"

0 commit comments

Comments
 (0)