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

Add documentation for the recently merged NDJSON support in vertx-web #18280

Merged
merged 1 commit into from
Jul 1, 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
49 changes: 49 additions & 0 deletions docs/src/main/asciidoc/reactive-routes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,55 @@ id: 3

----

=== Json Stream in NDJSON format

You can return a `Multi` to produce a newline delimited stream of JSON values.
Copy link
Contributor

@gastaldi gastaldi Jun 30, 2021

Choose a reason for hiding this comment

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

Suggested change
You can return a `Multi` to produce a newline delimited stream of JSON values.
You can return a `Multi` to produce a stream of http://ndjson.org/[NDJSON] (Newline-delimited JSON) values.

To enable this feature, you need to wrap the returned `Multi` using `io.quarkus.vertx.web.ReactiveRoutes.asJsonStream`:

[source, java]
----
@Route(path = "/people")
Multi<Person> people(RoutingContext context) {
return ReactiveRoutes.asJsonStream(Multi.createFrom().items(
new Person("superman", 1),
new Person("batman", 2),
new Person("spiderman", 3)
));
}
----

This method would produce:

[source, text]
----
{"name":"superman", "id": 1}
{"name":"batman", "id": 2}
{"name":"spiderman", "id": 3}

----

You can also provide strings instead of Objects, in that case the strings will be wrapped in quotes to become valid JSON values:

[source, java]
----
@Route(path = "/people")
Multi<Person> people(RoutingContext context) {
return ReactiveRoutes.asJsonStream(Multi.createFrom().items(
"superman",
"batman",
"spiderman"
));
}
----

[source, text]
----
"superman"
"batman"
"spiderman"

----

=== Using Bean Validation

You can combine reactive routes and Bean Validation.
Expand Down