This question came up while I was building a backend using JAX-RS but this can really apply to any REST API.
How does JAX-RS handle paths that might conflict due to param path variables? Suppose you have
@POST
@Path('createBox/{boxName}')
foo()
@POST
@Path('createBox/small')
bar()
And someone wants to call the first endpoint with a path param argument of small
. What happens in this case? If foo()
and bar()
had different parmas (maybe like @FormParam
) would that help differentiate? What if they were exactly the same with no arguments? Is the behavior non-deterministic?
Reference: RESTful Java with JAX-RS 2.0, 2nd Edition by Bill Burke
"/customers/{id: .+}
<-- getCustomer "/customers/{id: .+}/address"
<-- getAddress Precedence rules
The JAX-RS specification has defined strict sorting and precedence rules for matching URI expressions and is based on a most specific match wins algorithm.
{id}
or {id: .+}
. This sort is in descending order.{id}
Your example:
bar()
wins because as per rule 1, it has more literal characters
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.