Hi,
Rails 1.2 is just around the corner and the entire world is on the
verge of going REST crazy. There has been mention (from DHH at times)
of tutorials to show how to think RESTfully and fit in most
comfortably with the Rails way. An online store is always a popular
example and I went through the exercise to see how I might make a
store REST friendly. Below are the URL’s I came up with for a basic
store front with the common parts of a store interface for customers.
It could be that some of these URL’s should be disguised for a
friendlier user experience but the URL’s below are what I think of as
the raw REST-based URLs. If anyone has suggestions for changes I’d be
interested to read the reasons or see examples of other types of apps
and their URLs.
store splash page entrance
list of departments
GET http://store.com/departments/23
department 23 page
list of products in the department
GET http://store.com/cart_items;new?product=31
what we think of as the product 31 page
shows the form to create a new cart_item based on product 31 with
options and quantity
has the “add to cart” button
POST http://store.com/cart_items
create a new cart item based on form information including product id
redirects to cart
GET http://store.com/cart_items/612;edit
show the form to edit a cart item. If this cart item is for product 31
then we will see this as the product 31 page again but the button will
say “update” instead of “add to cart”.
PUT http://store.com/cart_items
updates a cart item based on form information including cart_item id
redirects to cart
DELETE http://store.com/cart_items/612
delete link shown on cart view page
removes an item from the cart
wants html: redirects to cart
wants js: sends javascript to update the cart view
GET http://store.com/cart_items
show the shopping cart
has the “checkout” button
GET http://store.com/puchases;new
form to checkout (shipping, credit card info)
has the “finalize” button
POST http://store.com/purchases
finalize the purchase
redirects to “thanks for purchase page”
GET http://store.com/purchases/55
the “thanks for purchase page” with a receipt.
GET http://store.com/purchases
customer order history with shipping status etc
GET http://store.com/customers;new
form to create an account
POST http://store.com/customers
create a new customer account
starts a new session like logging in would
redirect to “thanks for signing up page”
GET http://store.com/customers/77
show customer his details
GET http://store.com/customers/77;edit
edit customer details
PUT http://store.com/customers/77
update customer details
redirect to show customer details
GET http://store.com/sessions;new
customer login page (sessions are sort of singletons per customer)
DELETE http://store.com/sessions
customer logout
does not actually delete the session as another login can restore it.
redirect to “thank you for shopping” page or back to the page where
the logout was initiated if allowed there in logged out state
Peter
Fork JavaScript: http://forkjavascript.org