Issue
I need to call an external service with URL that looks like this...
GET https://api.staging.xxxx.com/locations?where={"account":"bob"}
This is not my service and I have no influence over it, and my codebase at the moment is using Spring WebClient.
WebClient.create("https://api.staging.xxxx.com/")
.get()
.uri(uriBuilder -> uriBuilder.path("locations?where={'account':'bob'}").build())
Since WebClient sees the { bracket it tries to inject a value into the URL, which I don't want.
Can anyone suggest how I can do with with Spring WebClient?
Otherwise I will revert to OKHttp or another basic client to sent this request.
Solution
You can use UriUtils#encodeQueryParams to encode the JSON param:
String whereParam = "{\"account\":\"bob\"}";
//...
uriBuilder
.path("locations")
.queryParam("where", UriUtils.encodeQueryParam(whereParam, StandardCharsets.UTF_8))
.build()
Answered By - lkatiforis
Answer Checked By - Pedro (JavaFixing Volunteer)