Is there a RESTful way to determine if a POST (or any other non-idempotent verb) will succeed? This may seem useful in cases where you essentially need to perform several idempotent requests for different services, any of which may fail. It would be nice if these requests could be executed in a "transaction" (i.e., with rollback support), but since this is not possible, an alternative is to check whether each request is successful before executing them.
For example, suppose I create an e-commerce system that allows people to buy t-shirts with special text printed on them, and this system requires integration with two different services: a t-shirt print service and a payment service. Each of them has a RESTful API, and any of them may fail. (For example, a printing company may refuse to print certain words on a T-shirt, say, and the bank may complain if the credit card has expired.) Is there a way to speculatively fulfill these two requests, so my system will only act if both requests look valid?
If not, can this be solved in a different way? Creating a resource using POSTwith status = pendingand changing it to status = completeif all requests are successful? ( DELETEmore complicated ...)
source
share