Alan Dean on RESTful checkout
2008-11-07 @ 14:22#
Alan Dean has posted his approach to a REST-ful shopping experience. he focuses on teh check out process. my post only included the loading of the cart itself.
reading this post by Alan Dean reminds me that following Fielding's REST constraints is not a simple thing.
one REST-ful way to approach shopping checkout is to model it as a series of resources that shoppers can create and manage throughout their shopping experience. below are my notes from an old project where i mapped out a basic set of shopping APIs using REST-ful constraints.
REST-y Shopping API
URI | Method | Status | Comments |
---|---|---|---|
/{user-id}/cart/ | GET | 200,404 | Retrieves the list of carts for this user. |
POST | 201,400 | Creates a new cart for this user. Returns Location:/{user-id}/cart/{cart-id}/ | |
/{user-id}/cart/{cart-id}/ | GET | 200,404 | Retrieves list of items in this cart. |
POST | 200,400 | Adds a new item to the cart. Returns Location:/{user-d}/cart/{cart-id}/{item-id} | |
DELETE | 200,404 | Deletes an existing cart for this user | |
/{user-id}/cart/{cart-id}/{item-id} | GET | 200,404 | Retrieves single item in the cart. |
PUT | 200,404 | Updates an existing item in the cart. | |
DELETE | 200,404 | Deletes an existing item in the cart. |
Notes
- The intial 'discovery' URI is GET /cart/. When receiving this request, the server will check for a valid user authentication token. If it exists, a 301 will be issued to GET /{user-id}/cart/. If a valid authentication token does not exist, a temporary value for {user-id} will be issued for this user and included in a transient cookie sent to the user-agent.
- The details of the payload contents (sku, price, quantity, etc.) are left to the specific implementation.
-
It is assumed the server will support more than one MIME-type for requests: JSON, XHTML, Atom, as well as
custom XML-based MIME-types if appropriate. It is also assumed the server will accept more than just
application/x-www-form-urlencoded
for PUT and POST.