The AutoRouter library simplifies the creation of REST APIs by automatically generating HTTP handlers for annotated methods in a controller object using pt.isel.autorouter.JsonServer. It provides features like annotation-based route definition and support for optional responses.
- Java 19
- Alexandre Severino - alexandreseverinowork@gmail.com
- Diogo Carichas - diogomcc5@gmail.com
- Francisco Castelo - lufinha2003@gmail.com
- Implement two approaches for generating HTTP routes:
- Reflection-based route discovery.
- Dynamic code generation for route handling.
- Enhance performance with JMH benchmarking.
- Add support for lazy file watching and streaming routes in
JsonServer.
-
Reflection-Based:
Implement a methodStream<ArHttpRoute> autorouterReflect(Object controller)that uses Java Reflection to scan for methods annotated with@AutoRouteand generate corresponding HTTP routes. Each method should handle requests based on its parameters and return type. Routes returning fulfilled, empty, or exceptionalOptionalvalues result in HTTP status codes200,404, and500, respectively. -
Dynamic Code Generation:
Replace the use of reflection with dynamically generatedArHttpHandlerimplementations for each eligible method in the controller. ImplementStream<ArHttpRoute> autorouterDynamic(Object controller)to generate and link these handlers, improving runtime performance.
- Use JMH to evaluate the performance difference between reflection-based and dynamic route generation.
- Benchmark commands:
./gradlew jmhJar java -jar autorouter-bench/build/libs/autorouter-bench-jmh.jar -i 4 -wi 4 -f 1 -r 2 -w 2