On 13 fév, 19:44, Polemann <
sco...@reynoldsphotography.com> wrote:
> Firstly, apologies for any REST people out there who find my example
> confusing I'm trying to understand.
>
> I'm interesting in using rest principles and links combined with a
> CQRS system but I'm not sure how commands etc fit in. Using an example
> of an CQRS Shopping Cart system which has commands like
> (AddItemToShoppingCart,ReplaceItemInCart,
> RemoveItemFromCart ,CheckoutShoppingCart) how would you approach the
> design of URL paths etc. The confusing bits are as follows:
>
> 1.CQRS splits the commands and queries but rest PUTs etc always result
> in a value being returned. Does this mean we can't really combine the
> concepts. I don't think rest support eventual consistency concepts.
> 2.If we allow Commands to be HTTP puts then that seems to violate the
> rest concepts of posting back an entire representation
>
> 3. Whats interesting to me is the links. I would love to allow a
> client to be able to ask for the cart and get the current possible
> links for the current user.
>
> GEThttp://
www.acart.com/customer/4d36e97b-e325-11ce-bfc1-08002be10318/cart/
>
> Returns:
>
> <cart>
> <created>2011-Jan-10 00:00:00 UTC</created>
> <customer>blah b</customer>
> <total>123.00 USD</total>
> <products>
> <id=1 qty=2 total='13.00 USD'>
> <id=2 qty=1 total='110.00 USD'>
> </products>
>
> <links>
> <dap:link rel="
http://www.acart.com/AddItemToShoppingCart"
> mediaType='application/vnd/acart+xml' uri="
http://www.acart.com/
> customer/4d36e97b-e325-11ce-bfc1-08002be10318/cart/
> AddItemToShoppingCart/>
> <dap:link rel="
http://www.acart.com/ReplaceItemInShoppingCart"
> mediaType='application/vnd/acart+xml' uri="
http://www.acart.com/
> customer/4d36e97b-e325-11ce-bfc1-08002be10318/cart/ReplaceItemInCart/>
> </links>
> </cart>
It depend on what problem you are trying to solve by making the update
of the cart asynchronous. Because if you look at amazon, the cart is
updated synchronously (the order is processed asynchronously, but it's
not the same thing).
So if there is no good reason to make updates of the cart
asynchronous, you should use PUT/POST/DELETE/... on your cart resource
and use the pending order pattern for example when you want to commit
it (
http://bitworking.org/news/201/RESTify-DayTrader)
If there is a problem of scalability (but updating a cart is not as
resource intensive as processing an order and there is no concurrency
problems with it because only one customer owns it), maybe you should
create and update the cart client side (and use the pending order
pattern when you want to commit), with Web SQL Db, Web Indexed Db,
LocalStorage, FlashStorage, Cookies, ... there are a lot of techniques
to persist the cart client-side (but maybe the customer will "loose"
his cart when it will connect with a different browser)
I think the biggest mismatch between REST and CQRS is the design of
uris, using differents uris for add/replace methods instead of using
methods on a ressource, you will have problems if you want to use
cache (PUT/POST/DELETE on a resource clean the cache for example).