I am creating a rest service that will match the inputs to find a resource. If the resource is found, it will return the resource otherwise it will create a new resource and will return that. As the call might change the server state (in case a new resource is created), this can not be GET call and should be a POST call. But there will be scenarios when the resource is found and no change is made to the server state.
What is the best way to expose this API. The options that come to my mind are:
Option 1: Expose single api as a POST api call.
Option 2: Expose 1 api for GET and another api for POST. The client will call GET and in case a resource is not found then make another call to create the resource.
I am leaning towards option 1 as I do not want the consumers to deal with the complexity of the operation and Option 2 will also have more latency owing to 2 trips to the server.
Please suggest any other pros/cons that I should consider for this design or if there are any other options.