Skip to content

Commit

Permalink
Add documentation about the Quarkus REST's @Separator
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jun 12, 2024
1 parent 3ab88f5 commit db9a4b7
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions docs/src/main/asciidoc/rest.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2865,6 +2865,65 @@ public class Endpoint {
}
----

Check warning on line 2866 in docs/src/main/asciidoc/rest.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Headings] Use sentence-style capitalization in 'Separating Query parameter values'. Raw Output: {"message": "[Quarkus.Headings] Use sentence-style capitalization in 'Separating Query parameter values'.", "location": {"path": "docs/src/main/asciidoc/rest.adoc", "range": {"start": {"line": 2866, "column": 1}}}, "severity": "INFO"}

==== Separating Query parameter values

Normally a collection of `String` values is used to capture the values used in multiple occurrences of the same query parameter.
For example, for the following resource method:

[source,java]
----
@Path("hello")
public static class HelloResource {
@GET
public String hello(@RestQuery("name") List<String> names) {
if (names.isEmpty()) {
return "hello world";
} else {
return "hello " + String.join(" ", names);
}
}
}
----

and the following request:

[source,http]
----
GET /hello?name=foo&name=bar HTTP/1.1
----

the `names` variable will contain both `foo` and `bar` and the response will be `hello foo bar`.

It is not uncommon however to need to convert a single query parameter into a collection of values based on some delimiting character. That is where the `@org.jboss.resteasy.reactive.Separator` annotation comes into play.

Check warning on line 2898 in docs/src/main/asciidoc/rest.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'. Raw Output: {"message": "[Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'.", "location": {"path": "docs/src/main/asciidoc/rest.adoc", "range": {"start": {"line": 2898, "column": 31}}}, "severity": "INFO"}

If we update the resource method to:

[source,java]
----
@Path("hello")
public static class HelloResource {
@GET
public String hello(@RestQuery("name") @Separator(",") List<String> names) {
if (names.isEmpty()) {
return "hello world";
} else {
return "hello " + String.join(" ", names);
}
}
}
----

and use the following request:

[source,http]
----
GET /hello?name=foo,bar HTTP/1.1
----

then the response will be `hello foo bar`.

==== Handling dates

Quarkus REST supports the use of the implementations of `java.time.Temporal` (like `java.time.LocalDateTime`) as query, path, or form params.

Check warning on line 2929 in docs/src/main/asciidoc/rest.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'params'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'params'?", "location": {"path": "docs/src/main/asciidoc/rest.adoc", "range": {"start": {"line": 2929, "column": 124}}}, "severity": "WARNING"}
Expand Down

0 comments on commit db9a4b7

Please sign in to comment.