Skip to content

Commit

Permalink
Add documentation for PR quarkusio#18182
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrp committed Jun 30, 2021
1 parent ada7316 commit 88e8844
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
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.
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

0 comments on commit 88e8844

Please sign in to comment.