Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code of the reactive routes guide #16345

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions docs/src/main/asciidoc/reactive-routes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,26 @@ import io.vertx.ext.web.RoutingContext;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped <1>
@ApplicationScoped // <1>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number seems be displayed well, why did you add "//"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, it didn't when I generated locally (the copy and paste was messed up).
I will check on the website.

public class MyDeclarativeRoutes {

// neither path nor regex is set - match a path derived from the method name
@Route(methods = HttpMethod.GET) <2>
void hello(RoutingContext rc) { <3>
@Route(methods = Route.HttpMethod.GET) // <2>
void hello(RoutingContext rc) { // <3>
rc.response().end("hello");
}

@Route(path = "/world")
String helloWorld() { <4>
String helloWorld() { // <4>
return "Hello world!";
}

@Route(path = "/greetings", methods = HttpMethod.GET)
void greetings(RoutingExchange ex) { <5>
@Route(path = "/greetings", methods = Route.HttpMethod.GET)
void greetings(RoutingExchange ex) { // <5>
ex.ok("hello " + ex.getParam("name").orElse("world"));
}
}
----

<1> If there is a reactive route found on a class with no scope annotation then `@javax.inject.Singleton` is added automatically.
<2> The `@Route` annotation indicates that the method is a reactive route. Again, by default, the code contained in the method must not block.
<3> The method gets a https://vertx.io/docs/apidocs/io/vertx/ext/web/RoutingContext.html[`RoutingContext`] as a parameter. From the `RoutingContext` you can retrieve the HTTP request (using `request()`) and write the response using `response().end(...)`.
Expand Down Expand Up @@ -653,7 +652,7 @@ example, adding header info, or specifying the return type on `void` methods mig

[source, java]
----
@OpenAPIDefinition(<1>
@OpenAPIDefinition( // <1>
info = @Info(
title="Greeting API",
version = "1.0.1",
Expand All @@ -669,10 +668,10 @@ example, adding header info, or specifying the return type on `void` methods mig
public class MyDeclarativeRoutes {

// neither path nor regex is set - match a path derived from the method name
@Route(methods = HttpMethod.GET)
@Route(methods = Route.HttpMethod.GET)
@APIResponse(responseCode="200",
description="Say hello",
content=@Content(mediaType="application/json", schema=@Schema(type=SchemaType.STRING)))<2>
content=@Content(mediaType="application/json", schema=@Schema(type=SchemaType.STRING))) // <2>
void hello(RoutingContext rc) {
rc.response().end("hello");
}
Expand All @@ -691,7 +690,6 @@ public class MyDeclarativeRoutes {
}
}
----

<1> Header information about your API.
<2> Defining the response

Expand Down Expand Up @@ -744,7 +742,7 @@ paths:
=== Using Swagger UI

Swagger UI is included by default when running in `dev` or `test` mode, and can optionally added to `prod` mode.
See <<openapi-swaggerui.adoc#use-swagger-ui-for-development,the Swagger UI>> Guide for more details.
See <<openapi-swaggerui.adoc#dev-mode,the Swagger UI>> Guide for more details.

Navigate to link:http://localhost:8080/q/swagger-ui/[localhost:8080/q/swagger-ui/] and you will see the Swagger UI screen:

Expand Down