๐ฃ๏ธ Router Setup¶
๐ Hands-on Example
Prefer to learn by doing? Explore the runnable API Gateway examples and see the router in action.
1๏ธโฃ Configure the Lambda¶
1 2 3 4 5 6 7 8 9 10 | |
2๏ธโฃ Configure the Router¶
Acai ships with a single pattern-based resolver. Provide either:
handlerPath: directory shorthand that automatically expands to**/*.js.handlerPattern: full glob expression when you want a custom naming convention.
Both inputs support dynamic segments such as {userId}.js and share identical behaviour.
๐๏ธ Directory-Style Shorthand (handlerPath)¶
๐ก Tip
When you introduce path parameters, name files using the {param}.js convention (for example {farmId}.js).
1 2 3 4 5 6 7 8 9 10 | |
๐งต Custom Glob (handlerPattern)¶
๐ง Pattern Ideas
Common globs include:
api/**/*.controller.jssrc/**/handler.*.jsservices/**/endpoint.js
1 2 3 4 5 6 7 | |
3๏ธโฃ Configure the Endpoint File¶
Every endpoint file should contain a function which matches an HTTP method in lower case. Most common are post, get, put, patch, delete, but this library does support custom methods, if you so choose. As long as the method of the request matches the function name, it will work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |