Home > Software design >  How to define REST API with to Parameter
How to define REST API with to Parameter

Time:12-17

I am currently working on a REST API for a project. In the process I should search for events. I would like to make an endpoint for searching events in a period. That is, specify two parameters with from - to.

For the search you normally take a GET operation. My question is now it makes sense to specify two parameters in the path or should I rather fall back to a POST operation for something like that.

Example for the path /Events{From}{To}

Is this even feasible with multiple parameters?

CodePudding user response:

If you are not making a change on the resource, you should use GET operation. More detailed explanation:

If you were writing a plain old RPC API call, they could technically interchangeable as long as the processing server side were no different between both calls. However, in order for the call to be RESTful, calling the endpoint via the GET method should have a distinct functionality (which is to get resource(s)) from the POST method (which is to create new resources).

GET request with multiple parameters: /events?param1=value1&param2=value2

GET request with an array as parameter: /events?param=value1,value2,value3

  • Related