I'm trying to query the https://transport.opendata.ch/ API. In this API, it is possible to filter the response to avoid a big payload (using ?fields[]=...
).
For example : http://transport.opendata.ch/v1/connections?from=Lausanne&to=Zurich&fields[]=connections/from&fields[]=connections/to
I'm using Spring Boot and Feign, here is my code :
@FeignClient(value = "transport", url = "${transport.url}")
public interface TransportClient {
@RequestMapping(method = GET, value = "/connections", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
Connections getConnections(@RequestParam("from") String from, @RequestParam("to") String to, @RequestParam("fields[]") String[] fields);
default Connections getConnections(String from, String to) {
return getConnections(from, to, new String[] {"connections/from", "connections/to"});
}
}
The trouble is the generated request :
As you can see, the url is encoded and the array is not correctly binded (using comma instead of several fields
in the url).
Is there any way to achieve this? If it cannot be done with FeignClient (Spring), maybe with Feign it is possible ?
Thanks for your help.
Your typical request looks like:
/api?fields=1&fields=2&fields=3
or
/api?fields=1,2,3
And the controller method is:
@RequestMapping(method = GET, value = "/api", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
Connections getConnections(@RequestParam("fields") List<String> fields)