This addon allows you to define HTTP routes in Javalin using the @Route annotation. All classes that implement the RouteManager interface are automatically detected and their annotated methods are registered on startup.
- Define routes using annotations
- Automatically registers routes on application startup
- Supports different HTTP methods
- Simple structure for modular APIs
- Build the project as a
.jar. - Add it to your project:
dependencies {
implementation files('libs/RouteRegistryAddon.jar')
}Use AutoRouteManager` to scan and register your annotated route classes:
public class Main {
public static void main(String[] args) {
Javalin app = Javalin.create().start(7002);
AutoRouteManager.registerRoutes(app, "de.nonbi.api.controller", false);
}
}Create a controller class and annotate your route method:
public class ExampleController implements RouteHandler {
@Route(path = "/example", method = Method.GET)
public static void exampleFunc(Context ctx) {
ctx.json("Example");
}
}You can also define custom responses for specific status codes:
public class ExampleController implements RouteHandler {
@Status(status = 404)
public static void exampleStatus(Context ctx) {
ctx.json("Page Not Found");
}
}This project is open-source and available under the MIT License.