We have a cart and cart has line items, now line items can be products, discount coupons, rewards and promotions. I am looking for some inputs in design consideration here. The backend is in Ruby on Rails.
for products I have already designed the URL to be
post: cart/line_items to create a line item for product
put: cart/line_items/:id to update the quantity
delete: cart/line_items/:id to remove the product
Now for Adding of samples and removing of samples, I am thinking of going this way.
get: cart/line_items/samples to get all the samples.
post: cart/line_items/samples to create a line item for sample
delete: cart/line_items/samples/:id to remove that sample from the cart
for discount coupon, rewards and promotions I am thinking of similar design. It would be great if experts can give me some inputs here.
samples
is a sub-resource ofline_items
andproducts
is not ? Seems strange...cart/line_items/samples
then may be I would change the implementation for products also, but this is still under consideration so I am looking for input if I should implement it this way or is there a better implementation.line_items
was somewhat my first thought. Would depend on how different those things are from each other. An alternative would be to omit theline_items
part in the URL (similar to shallow routing in the guide) and while keeping thesamples
controller using routes like/cart/samples/:id
. To show the whole cart you still could haveget: /cart/line_items
maybe. Would somewhat depend on who consumes this API, potentially a bit confusing to some people. With the params approach you would somewhat run the risk to have a swiss army knife controller.