✅ Which API design is better
I have orders that can be put in an issue status and then resolve that issue
There is two options:
1. The first one is having two different endpoints
PATCH /orders/{orderId}/create-issue
with the following body
and
PATCH /orders/{orderId}/resolve
with the following body
2. The second one is having a single endpoint
PATCH /orders/{orderId}/issue
and we either pass an issueDate + reason
OR resolveDate + solution
plus a validation if we pass inconsistent data (for example passing a body that contains a reason + solution
will result in a validation error since we can not create an issue and resolve it at the same time
Question: Which option is better and why?1 Reply
(why is everything PATCH? for example first couldn't be
POST /orders/{orderId}/issue
?)
anyway different endpoints for different actions to me is always better because it's more clear (different models for example, and in case you want to add behaviors again you know what to touch)
i would reserve single endpoint for bad situations where there are constraints like legacy stuff where the less you touch the less you break