Feign - URL encode path params
11,926
A simple config did it,
@RequestLine(value = "GET /products/{id}", decodeSlash = false)
@Headers({"Content-Type: application/json"})
ApiResponse getProduct(@Param("id") String productId) throws Exception;
The path param was correctly getting encoded but the RequestTemplate was decoding the URL again (decodeSlash=true by default) before sending out the request which was causing the issue.
Author by
NitishDeshpande
Updated on August 11, 2022Comments
-
NitishDeshpande almost 2 years
This is my contract,
@RequestLine("GET /products/{id}") @Headers({"Content-Type: application/json"}) ApiResponse getProduct(@Param("id") String productId) throws Exception;
I want to fetch the product with id = "a/b",
If I send this as a param to
getProduct("a/b")
then the URL that is formed is
http://api/products/a/b
and I am getting a 404 instead the url should behttp://api/products/a%2Fb
Is there a way around this?