1

So if I would want to get say a User data, passing user id, I will use GET verb and pass user id in query string with route something like this

[HttpGet]
[Route("user/{userId}")]

But what if I want to fetch user based on multiple input parameters. Say by UserType, Salary etc.

Then passing these multiple values or complex object values in querystring will not make sense, I will have to pass them in body and for that I will have to use the POST verb.

But is it correct to use POST verb to get data?

If not, which verb should I use for these cases

Pawan Nogariya
  • 8,330
  • 12
  • 52
  • 105
  • 1
    This thread has some interesting input on this: https://stackoverflow.com/questions/29203447/managing-complex-data-with-get – SnowGroomer Aug 04 '21 at 12:26
  • @stuartd Yes, but is it correct to pass complex data in query string, that too is also wrong I guess. That is why I asked the question – Pawan Nogariya Aug 04 '21 at 12:37

1 Answers1

1

I would say it is ok to use POST in this situation. A query string that is too long can also cause problems when it comes to limits to the url length of webrowsers or servers.

But if you want to be correct about the verbs you could POST and create a filter object and return its id, then do your GET request including the filterId.

Your backend can now retrieve the previously created filter and apply it.

Random12b3
  • 159
  • 7