Search code examples
restrestful-architecture

Restful way to validate a resource


Imagine I have a resource of a some special case of an e-commerce application /cart in my API that supports some CRUD operations: GET, POST

I want to have a service that validates if the cart is correct (stock availability, etc...) so I need all the cart information, but I don't want to store partial states of the cart, that's why PUT is not supported for this resource.

The question is which method and path is the correct to do this kind of service in a Restful way?


Solution

  • I think if you want to build a restful web service, you should not bind too much business logic in it.

    Restful service should be think as an infrastructure of the system. It provides consistent api to allow others to access the resource.

    You could build a bussiness layer upon the restful resources, in this layer you can do the complex business logic, for example, checking stock availability(maybe underlying accessing the stock resource), or making a payment(maybe underlying accessing the payment resources and the product resources)