Skip to content

Commit 2c9f665

Browse files
committed
Javadocs for parameter lookup.
1 parent 1e8f86d commit 2c9f665

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

‎docs/asciidoc/context.adoc‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ registry while the request it belongs to is being processed.
4444

4545
=== Parameters
4646

47-
There are several parameter types: `header`, `cookie`, `path`, `query`, `form` and `multipart`.
48-
All them share an unified/type-safe API for accessing and manipulating their values.
47+
There are several parameter types: `header`, `cookie`, `path`, `query`, `form`, `multipart`,
48+
`session` and `flash`. All them share a unified/type-safe API for accessing and manipulating their values.
4949

5050
We are going to describe them briefly in the next sections, then go into specific features of the
5151
<<Value API>>.
5252

53+
There is also a <<context-parameters-parameter-lookup,parameter lookup>> feature by which you can access a parameter from any combination
54+
of the above types with well-defined priority.
55+
5356
==== Header
5457

5558
HTTP headers allow the client and the server to pass additional information with the request or the
@@ -568,6 +571,41 @@ Flash attributes are implemented using an `HTTP Cookie`. To customize the cookie
568571
install(FlashScope(Cookie("myflash").setHttpOnly(true)))
569572
----
570573

574+
==== Parameter Lookup
575+
576+
You can search for parameters in multiple sources with an explicitly defined priority using the
577+
javadoc:Context[lookup] or javadoc:Context[lookup, java.lang.String, ParamSource...] method:
578+
579+
.Java
580+
[source,java,role="primary"]
581+
----
582+
get("/{foo}", ctx -> {
583+
String foo = ctx.lookup("foo", ParamSource.QUERY, ParamSource.PATH).value();
584+
return "foo is: " + foo;
585+
});
586+
587+
get("/{foo}", ctx -> {
588+
String foo = ctx.lookup().inQuery().inPath().get("foo").value();
589+
return "foo is: " + foo;
590+
});
591+
----
592+
593+
.Kotlin
594+
[source,kotlin,role="secondary"]
595+
----
596+
get("/{foo}") { ctx ->
597+
val foo = ctx.lookup("foo", ParamSource.QUERY, ParamSource.PATH).value()
598+
"foo is: $foo"
599+
}
600+
601+
get("/{foo}") { ctx ->
602+
val foo = ctx.lookup().inQuery().inPath()["foo"].value()
603+
"foo is: $foo"
604+
}
605+
----
606+
607+
In case of a request like `/bar?foo=baz`, `foo is: baz` will be returned since the query parameter
608+
takes precedence over the path parameter.
571609

572610
include::value-api.adoc[]
573611

‎docs/asciidoc/mvc-api.adoc‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ MVC routes (Singleton vs Non-Singleton routes).
220220

221221
HTTP parameter provision is available via `*Param` annotations.
222222

223+
There is also a javadoc:annotations.Param[] annotation which allows to retrieve parameters from
224+
<<mvc-api-parameters-multiple-sources,multiple sources>>.
225+
223226
==== Header
224227

225228
Provisioning of headers is available via javadoc:annotations.HeaderParam[] annotation:
@@ -600,6 +603,36 @@ class MyController {
600603

601604
<1> All context attributes must be set as arguments. They must be declared as `Map<String, Object>`
602605

606+
==== Multiple Sources
607+
608+
You can use the javadoc:annotations.Param[] annotation to search for a parameter in multiple sources.
609+
The sources and their precedence can be specified as follows:
610+
611+
.Multiple Sources
612+
[source, java, role = "primary"]
613+
----
614+
public class FooController {
615+
616+
@GET("/{foo}")
617+
public String multipleSources(@Param({ QUERY, PATH }) String foo) {
618+
return "foo is: " + foo;
619+
}
620+
}
621+
----
622+
623+
.Kotlin
624+
[source, kotlin, role = "secondary"]
625+
----
626+
class FooController {
627+
628+
@GET("/{foo}")
629+
fun multipleSources(@Param(QUERY, PATH) foo: String) = "foo is: $foo"
630+
}
631+
----
632+
633+
In case of a request like `/bar?foo=baz`, `foo is: baz` will be returned since the query parameter
634+
takes precedence over the path parameter.
635+
603636
=== Responses
604637

605638
==== Status Code

0 commit comments

Comments
 (0)