Skip to content

ketsugi123/AutoRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autorouter Project Summary

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.

Tools used

  • Java 19

Colaborators

Objectives

  1. Implement two approaches for generating HTTP routes:
    • Reflection-based route discovery.
    • Dynamic code generation for route handling.
  2. Enhance performance with JMH benchmarking.
  3. Add support for lazy file watching and streaming routes in JsonServer.

Implementation Details

1. HTTP Route Generation

  • Reflection-Based:
    Implement a method Stream<ArHttpRoute> autorouterReflect(Object controller) that uses Java Reflection to scan for methods annotated with @AutoRoute and generate corresponding HTTP routes. Each method should handle requests based on its parameters and return type. Routes returning fulfilled, empty, or exceptional Optional values result in HTTP status codes 200, 404, and 500, respectively.

  • Dynamic Code Generation:
    Replace the use of reflection with dynamically generated ArHttpHandler implementations for each eligible method in the controller. Implement Stream<ArHttpRoute> autorouterDynamic(Object controller) to generate and link these handlers, improving runtime performance.


2. Performance Benchmarking

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors