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
+34-41Lines changed: 34 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -574,38 +574,6 @@ Keep the following in mind when authoring middlewares for Event Handler:
574
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.
575
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.
576
576
577
-
#### Staging area
578
-
579
-
**This should go under the Router area since we haven't introduced it yet**
580
-
581
-
Middleware functions used in the Router instance will apply to all API routes and will always be processed first in the order they are added to the Router. Route specific middleware added to each route will then be processed in the order they were added in the route definition.
582
-
583
-
???+ tip
584
-
**Router Middleware processing Order**
585
-
586
-
1. Global middlewares defined on the parent Router
587
-
2. Route specific Middlewares
588
-
589
-
To maximize the re-usability of your middleware functions we recommend using the **BaseRouter** or **Router** classes providing the **current_event** object contains the required fields for your middleware.
590
-
591
-
???+ warning "Ensure your middleware calls the Next one in the chain"
592
-
The middleware stack processing relies on each middleware function calling the next and also returning the reponse or raising an exception. If you do not pass control to the next middleware function in the chain, your API route handler will never be called.
You can use the `Response` class to have full control over the response. For example, you might want to add additional headers, cookies, or set a custom Content-type.
@@ -743,15 +711,6 @@ Let's assume you have `split_route.py` as your Lambda function entrypoint and ro
The application of middleware functions for split routers is the same as using the main Resolver classes. When the split routes are combined in the API Rest resolver all Router based and route base middleware will be merged into the parent instance.
749
-
750
-
???+ info "Split Router Middleware processing Order"
751
-
1. Global Middleware defined on the parent Router
752
-
2. Global Middleware for each split Router, in the order they are included
753
-
3. Route specific Middlewares
754
-
755
714
#### Route prefix
756
715
757
716
In the previous example, `split_route_module.py` routes had a `/todos` prefix. This might grow over time and become repetitive.
@@ -838,6 +797,40 @@ This is a sample project layout for a monolithic function with routes split in d
838
797
└── test_main.py # functional tests for the main lambda handler
839
798
```
840
799
800
+
#### DRAFT Router Middlewares
801
+
802
+
Middleware functions used in the Router instance will apply to all API routes and will always be processed first in the order they are added to the Router. Route specific middleware added to each route will then be processed in the order they were added in the route definition.
803
+
804
+
???+ tip
805
+
**Router Middleware processing Order**
806
+
807
+
1. Global middlewares defined on the parent Router
808
+
2. Route specific Middlewares
809
+
810
+
To maximize the re-usability of your middleware functions we recommend using the **BaseRouter** or **Router** classes providing the **current_event** object contains the required fields for your middleware.
The application of middleware functions for split routers is the same as using the main Resolver classes. When the split routes are combined in the API Rest resolver all Router based and route base middleware will be merged into the parent instance.
828
+
829
+
???+ info "Split Router Middleware processing Order"
830
+
1. Global Middleware defined on the parent Router
831
+
2. Global Middleware for each split Router, in the order they are included
832
+
3. Route specific Middlewares
833
+
841
834
### Considerations
842
835
843
836
This utility is optimized for fast startup, minimal feature set, and to quickly on-board customers familiar with frameworks like Flask — it's not meant to be a fully fledged framework.
0 commit comments