Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use complex parameters with Web API RESTful Get method

For RESTful APIs, I need to use get for retrieving a list, however I want to pass some the following complex parameter as an input for the method.

{
  "Filters": [
    {
      "FieldName": "sample string 1",
      "FieldValue": "sample string 2"
    },
    {
      "FieldName": "sample string 1",
      "FieldValue": "sample string 2"
    }
  ],
  "SortField": "sample string 1",
  "SortValue": 0,
  "Page": 2,
  "PageSize": 3
}

How the parameter will be passed since I cannot use the RequestBody in a Get method, and if I make it Post, it won't be RESTful.

like image 954
Homam Avatar asked Dec 18 '22 17:12

Homam


1 Answers

Reading REST API using POST instead of GET and others, it doesn't seem that there is a canonical definition of Restful that forbids using POST for what you want.

In this case the rule could be "do what's best".

Further, since it appears that you own both the host and client ends of the process, there's not much reason to avoid POST.

Fundamentally, there's no simple way to incorporate serialized json in a URL, which is what GET would need.

like image 61
dkretz Avatar answered Jan 18 '23 02:01

dkretz