One-to-one relationships and subresources in REST APIs
developers.lyst.com
developers.lyst.com
I would normally go for something like `/cart?user_id={{id}}`, forcing API consumers to pass in the `user_id` (possibly reluctantly defaulting the value to `current_user_id` for convenience.)
My first thought was that POSTing to the cart (or the user) is the most obvious way to add items? But then I thought maybe you just PUT to /api/cart/item_number? That would be cool.
what I do for my carts is PATCH to /carts/<cid>/items to partial mass-update all items with items[iid][qty]=x
EDIT: It's as if you're arguing based on some theory you've read rather than on what we're discussing.
however, when you do PUT, you leave it up to the client to choose the destination id (if it is not already known), this is not good. You should add items by POSTing to an item factory such as /cart/items. The cart will create the item(s) for you and that item resource will almost certainly hold additional data that was not passed in from the client (usually just SKU + qty) such as base price, calculated discounts, tax, etc. a PUT would not be appropriate as it requires the entire resource to be replaced (or created) at the destination specified by the client. the client rarely knows the entire resource (or has the permission to modify it at will), so follow-up updates should be done via PATCH /cart/items/<iid> or (mass) PATCH /cart/items
Is the user bringing a cart (/user/<USER_ID>/cart/<CART_ID>)?
Is he bringing his own cart (/user/<USER_ID>/cart)?
Is the store supplying a cart for the user (/cart)?
Applying real world objects and thinking, makes more sense in my mind. The third option instinctively is the most suitable way to go (IMO).
I'm not sure where this stands in the standards track.
For example I want to get 40 rooms, and for 20 of them, I want to get up to 20 participants in the rooms. My JS code shouldn't have to care about the batching. It should just send out batched requests, and the callbacks should be called.
On the client side, we have this: http://platform.qbix.com/guide/patterns -- see Q.batcher.factory
But on the server side, we've had to implement our own format to get that implemented.
I must say I think that's quite by design. The semantics of a PATCH request is to modify the given resource.
Facebook have their own, similar method of supporting batched calls through the Graph API [3], and this even permits you to specify dependencies between operations in a single request using JSONPath [4].
[1] http://jsonapi.org/ [2] http://jsonapi.org/extensions/bulk/ [3] https://developers.facebook.com/docs/graph-api/making-multip... [4] https://code.google.com/p/jsonpath/
to get a specific other user's cart, you would query GET /users/<user_id>/carts and then a follow-up GET directly to the cart resource
regarding authorization, just pass a session token in the query string if you're against implicit headers/cookies.
this is not necessarily true. if you're managing users, then they are resources like anything else. but users can also act as contexts for operations and access, including auth/prmissions, audit/logging.
when the user is acting as a context, it should be implicit and stored in a session, with an initialized token after login.
http://stackoverflow.com/questions/6068113/do-sessions-reall...
though your sessions do maintain some server context. you cannot let the client decide when to expire a session, for example. pure REST is a pipe dream. there are many things that work sub-optimally if adhering to strict rest as it pertains to http. see the second answer in that thread.
The payload of the requests will be encrypted (assuming HTTPS), but the urls are not. So I think you're opening the door to session hijacking in this way.
edit: I was wrong about this. The URL will be confidential in transit. Thanks for setting me straight.
I still think it is not a great design, but for different reasons: the url will be visible in your browser history and on the server side in the logs.
hostname is also encrypted (cause it's a header), though your insecure DNS pre-queries will give that away to anyone listening on the wire.