Search code examples
restgetquery-stringrequest-mappingget-mapping

What is best practice to send single parameter name multiple times in HTTP GET Request (status=Saved&status=Published)?


This is total new module to be added in our application.

In Get Request, End user requires data on basis of status Saved as well as Published. The designer suggest to send status like below:

posts?status=Saved&status=Published&_sort=date&_order=asc    

The above URL does not appears extendable as if user require data on 5 statuses in future it will keep n adding status& . (I need to write Spring Boot request mapping accordingly)

Could anyone who worked extensively on Rest API more better way to fix this approach as i think Post Request is of no use here as user is getting the data?

Edit: Also i am not sure if using _ (underscore) is fine?


Solution

  • Send the statuses like below. I prefer to send one character status (S=saved, P=published) to controller as it is short and neat.

    posts?status=S,P&_sort=date&_order=asc

    and map statuses to a List in controller like below

    @RequestParam List<String> status