Let's say I have an online store with a "shopping cart" function, and I want to implement the "empty shopping cart" link using RESTful.
For simplicity, let's say my resources are a Basket containing CartItems, each of which has a Product. My URIs can be:
# add a product to the current user Cart
POST / products / product_id / cart_items /
# remove a product from the current user Cart
DELETE / cart_items / cart_item_id /
If so, what will a RESTful URI look like for an empty cart link?
Instead, I could think of Cart as a universal holder for Actions ( as described here ):
# add a product
# form data contains eg, product_id = 123 & action = add
POST / carts / cart_id / actions /
# remove a product
# action_id is the id of the action adding product 123
DELETE actions / action_id
# empty cart
# form data contains action = clear
POST / carts / cart_id / actions /
This approach seems more complicated than necessary. What would be better?
source
share