I’ve been working on a site but can’t seem to come up with a good design for its implementation. Here’s the flow:
user selects a shirt. User selects what size of shirt. User says what they want on it, and it is added to their cart. They can repeat or go to checkout.
the problem i’m having is for a line_item to be added to the cart, it needs a sku and a design record. The design record gets created at the point where they add it to their cart.
Right now, I have everything in a store_controller.
So I have methods like prepare_for_cart, add_shirt_to_cart, confirm_order, add_design, show_receipt… I don’t know how I could possibly break this stuff up into something restful.
So is it something that can always be worked out with REST, or are there truly some cases where it doesn’t work? What’s one to do to try and make this more maintainable and understandable? are there other applicable design patterns to consider?
In almost all cases REST is a possibility, but it’s not always the best possible choice.
If for instance you have an endpoint that should send out an email, you could create unique urls for these:
Similarly with your design, it would be possible to have urls like:
One thing that may help you think about this, is to stop thinking about urls and most importantly methods. only think about the documents you’re sending back and forward. The ‘RE’ in REST stands for representation, the GET, PUT, DELETE methods are just simple means to transfer the representation from client to server.
Edit
Well, REST is a very nice design. It’s not designed to be easy to implement, or even consume.. but it’s designed for robustness, something that can last 10 years and remain backwards compatible. Just like the web itself.
This investment may not be worth it for you, you may simply want to use an approach that’s easier to implement. Sure, you won’t be REST-compliant™. It’s just not for everyone, it takes one look at how the average api from any big vendor works, to realize many have decided to not apply a RESTful design.
So figure out the pro’s and cons for yourself; technical merit is the only thing that counts in the end.
The fact that you have to ask ‘how do I make this RESTful’ tells me you need to do more research first, and figure the what and why of REST in general.