I have a REST API in my server, where the List operation (that should be implemented using the GET method) receives multiple parameters from the client:
Due to this complex object for filtering the search, I need to define the List as POST, what I think that it's not a good idea, as REST defines the list operation as GET.
My question is simple: there exists any way to solve this using a GET method, avoiding to call it with an huge URL with parameters?
Thanks to your answers. It seems that this question is really concerning, because there is not a clear valid answer. It's up to the developer to decide how to deal with it.
So it seems that the best approach is the first one: use GET and build huge URIs.
you can convert your object to json and then url-encode the json text string so you can put it in a single parameter.
To make your url-encoded json string shorter you could remove all the default values from your object prior to converting it to a json text string.
Long query strings in get requests are quite common, so no need to worry about those. There is a limit to how long a query string may become.
I encountered a similar issue. I had to send a huge list, but I still had to use GET. I ended up encoding the string with an encoding algorithm and sending it like that. I decode the list in the backend. I also have a param which specifies if the call is made encoded or not and so, the endpoint can be used both encoded and un-encoded.
You can use this approach for multiple parameters as well. You can send your list of parameters like param1:value1,param2:value2 encoded and decode it on the backend.
Another approach I investigated was to use Base 62 for converting numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With