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 about the Quarkus REST's @Separator #41146

Merged
merged 1 commit into from
Jun 12, 2024
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
59 changes: 59 additions & 0 deletions docs/src/main/asciidoc/rest.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2863,11 +2863,70 @@
+ "/" + valueOf + "/" + list;
}
}
----

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"}
Furthermore, it provides the `@org.jboss.resteasy.reactive.DateFormat` annotation, which can be used to set a custom expected pattern.
Otherwise, the JDK's default format for each type is used implicitly.

Expand Down