From ce0f62e56088aebe40a5aa6cd0f07689700604c8 Mon Sep 17 00:00:00 2001 From: dzikoysk Date: Sat, 29 Jun 2024 00:41:13 +0200 Subject: [PATCH] GH-40 Update annotated routing example in README --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dd14026..a13d3b6 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ some people may even say that it's the only one. Take a look on the example below to see how it looks like: ```java +import static io.javalin.community.routing.annotations.AnnotatedRouting.Annotated; + // register endpoints with prefix @Endpoints("/api") static final class ExampleEndpoints { @@ -125,15 +127,15 @@ static final class ExampleEndpoints { } public static void main(String[] args) { - Javalin.create(config -> { + Javalin.createAndStart(config -> { // prepare dependencies - ExampleEndpoints exampleEndpoints = new ExampleEndpoints(new ExampleService()); + var exampleService = new ExampleService(); // register endpoints - AnnotatedRoutingPlugin routingPlugin = new AnnotatedRoutingPlugin(); - routingPlugin.registerEndpoints(exampleEndpoints); - config.plugins.register(routingPlugin); - }).start(7000); + config.router.mount(Annotated, routing -> { + routing.registerEndpoints(new ExampleEndpoints(exampleService)); + }); + }); // test request to `saveExample` endpoint HttpResponse saved = Unirest.post("http://localhost:7000/api/hello")