You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/event_handler/api_gateway.md
+5-6Lines changed: 5 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -370,7 +370,7 @@ stateDiagram
370
370
371
371
EventHandler: GET /todo
372
372
Before: Before response
373
-
Next: get_response()
373
+
Next: next_middleware()
374
374
MiddlewareLoop: Middleware loop
375
375
AfterResponse: After response
376
376
MiddlewareFinished: Modified response
@@ -394,8 +394,7 @@ A middleware is a function you register per route to **intercept** or **enrich**
394
394
Each middleware function receives the following arguments:
395
395
396
396
1.**app**. An Event Handler instance so you can access incoming request information, Lambda context, etc.
397
-
2.**get_response**. A function to get the next middleware or route's response.
398
-
3.**`**kwargs`**. Middleware keyword arguments that are propagated in the chain.
397
+
2.**next_middleware**. A function to get the next middleware or route's response.
399
398
400
399
Here's a sample middleware that extracts and injects correlation ID, using `APIGatewayRestResolver` (works for any [Resolver](#event-resolvers)):
401
400
@@ -406,7 +405,7 @@ Here's a sample middleware that extracts and injects correlation ID, using `APIG
406
405
```
407
406
408
407
1. You can access current request like you normally would.
409
-
2. [Shared context is available](#sharing-contextual-data) to any middleware, Router and App instances. <br/ ><br/> Alternatively, you can use `**context` kwargs which will only be available for middlewares.
408
+
2. [Shared context is available](#sharing-contextual-data) to any middleware, Router and App instances.
410
409
3. Get response from the next middleware (if any) or from `/todos` route.
411
410
4. You can manipulate headers, body, or status code before returning it.
412
411
5. Register one or more middlewares in order of execution.
@@ -506,7 +505,7 @@ While there isn't anything special on how to use [`try/catch`](https://docs.pyth
506
505
507
506
=== "Unhandled exception from route handler"
508
507
509
-
An exception wasn't caught by any middleware during `get_response()` block, therefore it propagates all the way back to the client as HTTP 500.
508
+
An exception wasn't caught by any middleware during `next_middleware()` block, therefore it propagates all the way back to the client as HTTP 500.
@@ -570,7 +569,7 @@ Middlewares can add subtle improvements to request/response processing, but also
570
569
Keep the following in mind when authoring middlewares for Event Handler:
571
570
572
571
1.**Use built-in features over middlewares**. We include built-in features like [CORS](#cors), [compression](#compress), [binary responses](#binary-responses), [global exception handling](#exception-handling), and [debug mode](#debug-mode) to reduce the need for middlewares.
573
-
2.**Call the next middleware**. Return the result of `get_response(app, **kwargs)`, or a [Response object](#fine-grained-responses) when you want to [return early](#returning-early).
572
+
2.**Call the next middleware**. Return the result of `next_middleware(app)`, or a [Response object](#fine-grained-responses) when you want to [return early](#returning-early).
574
573
3.**Keep a lean scope**. Focus on a single task per middleware to ease composability and maintenance. In [debug mode](#debug-mode), we also print out the order middlewares will be triggered to ease operations.
575
574
4.**Catch your own exceptions**. Catch and handle known exceptions to your logic. Unless you want to raise [HTTP Errors](#raising-http-errors), or propagate specific exceptions to the client. To catch all and any exceptions, we recommend you use the [exception_handler](#exception-handling) decorator.
576
575
5.**Use context to share data**. Use `app.append_context` to [share contextual data](#sharing-contextual-data) between middlewares and route handlers, and `app.context.get(key)` to fetch them. We clear all contextual data at the end of every request.
0 commit comments