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 -
- Part of request as json object
OR - In the form of query parameters as (POST /api/someresource?param1=value1¶m2=value2)
which option is most suitable?
Is there any guideline which suggests to choose one among above two methods based on the fact -
- that these are mandatory parameters so we should not use query parameters?
- these are not logically related but just a input to create a resource; so we can use query parameters?
/api/someresource?param1=value1¶m2=value2
is likely aGET
request and notPOST
request. If your request changes a state on the server then usePOST
. If its only a read operation useGET
.