Skip to content

Commit

Permalink
Merge pull request #18280 from ntrp/main
Browse files Browse the repository at this point in the history
Add documentation for the recently merged NDJSON support in vertx-web
  • Loading branch information
geoand authored Jul 1, 2021
2 parents c364ea4 + 88e8844 commit f974aa7
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions docs/src/main/asciidoc/reactive-routes.adoc
Original file line number Diff line number Diff line change
@@ -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.
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.

0 comments on commit f974aa7

Please sign in to comment.