Skip to content

Commit

Permalink
GH-40 Update annotated routing example in README
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk authored Jun 28, 2024
1 parent 104cf20 commit ce0f62e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit ce0f62e

Please sign in to comment.