0

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?

fatherazrael
  • 5,511
  • 16
  • 71
  • 155
  • Why shouldn't the "multiple occurrences of the same parameter name" approach work? https://medium.com/@AADota/spring-passing-list-and-array-of-values-as-url-parameters-1ed9bbdf0cb2 – Smutje Nov 15 '19 at 10:23
  • @Smutje: There are 10 Statuses in database so will it not create any problem to have big URL or alternative to this?? – fatherazrael Nov 15 '19 at 10:24
  • "What Is the Maximum Length of a URL? Technically speaking, your URL should never be longer than 2,048 characters. Any long than this and Internet Explorer won’t be able to load your page." – Smutje Nov 15 '19 at 10:25
  • @Smutje: So in that case we need to have Post Request in which we get Data? – fatherazrael Nov 15 '19 at 10:26
  • 1
    In what case do you need what? Don't try to think of any possibility, solve actual problems – Smutje Nov 15 '19 at 10:27
  • @Smutje Just use case if URL getting big due to multiple statuses (of course not 2048 as of now in my case), then we should use POST in place of GET to send data? – fatherazrael Nov 15 '19 at 10:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/202394/discussion-between-fatherazrael-and-smutje). – fatherazrael Nov 15 '19 at 10:31

1 Answers1

1

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
Dipin
  • 1,085
  • 6
  • 19