Search code examples
javaspring-bootrestcontrollerhttp-get

How can I send a String list as param with a lot of items in a get mapping request in Spring boot?


I have a Spring boot controller with a get request method to be used as Rest API, this one.

The third param, ids, is a String list. Usually it is not a problem, but sometimes this list needs to have more than a six hundreds of items, and it launch an error because length limit on the URI.

@GetMapping("/mhcil/details")
public ResponseEntity findDetails(
        @RequestParam(name = "from")  String from,
        @RequestParam(name = "to")  String to,
        @RequestParam(name = "cil", required = false) List<String> cils,
        @RequestParam(name = "responsetype") ResponseType responseType,
        @NotNull @RequestHeader(value = "Oauth") String token

I tried to move all the parameters to a class, but since is a GET request it doesn't solve the issue with the URI characters limit. I have the patch to change from @RequestParam to a @RequestBody and use a POST or PUT request instead of get, but I will prefer to solve it maintaining the GET request.

I have started thinking of sending a compressed String and then uncompress it in the controller, but I'm not sure about how to do it.

Can anyone provide me a hint about how can I proceed to solve it?

Thanks in advance


Solution

  • You could change the server.max-http-header-size default setting from 8kB to whatever size you need, but i would recommend using POST instead. See: https://stackoverflow.com/a/27950790/3684747