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/features/event-handler/rest.md
+33-5Lines changed: 33 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -565,15 +565,43 @@ Please [check this issue](https://github.com/aws-powertools/powertools-lambda-ty
565
565
566
566
### Split routers
567
567
568
-
!!! note "Coming soon"
569
-
570
568
As applications grow and the number of routes a Lambda function handles increases, it becomes natural to either break it into smaller Lambda functions or split routes into separate files to ease maintenance.
571
569
572
-
Currently, the TypeScript event-handler's Router class doesn't provide a way to compose multiple router instances, forcing developers to define all routes in a single file or manually merge route definitions.
570
+
The `Router` class provide an `includeRouter` method to compose multiple router instances allowing developers to define routes in multiple files and merge route definitions. You will be able to define routes in separate files and import them into a main router file, improving code organization and maintainability.
571
+
572
+
!!! note "Merging with Global Middleware"
573
+
When merging two `Router` instances together, if you have a global middleware defined in one of your instances, the global middleware gets applied to the all the merged routes.
574
+
575
+
Let's assume you have `index.ts` as your Lambda function entrypoint and routes in `split_route.ts`. This is how you'd use the `includeRouter` feature.
In the previous example, `split_route.ts` routes had a `/todos` prefix. This might grow over time and become repetitive.
592
+
593
+
When necessary, you can set a prefix when including a `Router` instance. This means you could remove `/todos` prefix altogether.
573
594
574
-
Once this feature is available, you will be able to define routes in separate files and import them into a main router file, improving code organization and maintainability.
595
+
=== "split_route_prefix.ts"
575
596
576
-
Please [check this issue](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4481) for more details and examples, and add 👍 if you would like us to prioritize it.
0 commit comments