what is best option to pass parameters in REST api - POST type of method?

1.6k Views Asked by At

I am designing a REST api for creating a resource using POST method. This create call accepts 4 parameters which are mandatory but not logically related to each other. So I have two options to accept these 4 input parameters as -

  1. Part of request as json object
    OR
  2. In the form of query parameters as (POST /api/someresource?param1=value1&param2=value2)

which option is most suitable?

Is there any guideline which suggests to choose one among above two methods based on the fact -

  1. that these are mandatory parameters so we should not use query parameters?
  2. these are not logically related but just a input to create a resource; so we can use query parameters?
1

There are 1 best solutions below

4
On

/api/someresource?param1=value1&param2=value2 is likely a GET request and not POST request. If your request changes a state on the server then use POST. If its only a read operation use GET.