mozvat / WSPAPIPrototype

Web Services 2.0 prototype work.
1 stars 2 forks source link

Multiple operations for http verbs #23

Open jsermini opened 11 years ago

jsermini commented 11 years ago

The design seems truly representational, so that is a nice, and lends to ease of use. But I do have a couple of questions on that format. -How would be differentiate between different types of POST, GET, etc. -Would we Redesign the Noun/Verb? This might be less intuitive at times. -Or add a verb (method name) to the URL? -This is how I had done this in the past, seemed less "restfull"

Here is my example, how would we differentiate what to do on a post to Credits? How would we know what action to take here: -These three are similar and seem logical to be POST -AddCredits -CloseTransaction -CloseTransactionWith Sku

esear commented 11 years ago

I think this the root of the discussion we need to finalize. I think we need to identify the resource model we are looking to represent (i.e. that excel doc I sent you).

To your question above, credits seems to be an attribute (or sub-resource) of a loyalty resource called /program (maybe?) and you would add credits to a /program by submitting a POST against the resource.

OPTION 1: credits is part of the resource model POST /loyalty/program/[programID]/credits OR POST /loyalty/program/credits?programID= The body of the post could be as simple as {"credits": "1"} OR {"credits": "-5"} the number representing what we need to add to the current credit balance.

OPTION 2: credits are an attribute to a program POST /loyalty/program/[programID] body of the post: here is where my dev skills end. Would we need to provide the entire object or just changed elements? I presume would could just provide the credits attribute and the server would know to just update that value. {"credits": "1"} OR {"credits": "-5"}

We could also make the client manage the math, and have them just put what the credit total should be. This has the benefit of being idempotent. PUT /loyalty/program/[programID] body of the PUT, {"credits": "9"} - 9 representing what we need to update the total credits to.

esear commented 11 years ago

To your other item (CloseTransaction) I imagine the resource as /transaction and we could handle an operation like 'close' with any of these approaches: (use PUT because it is an idempotent call) PUT /transaction/[transactionID]/close PUT /transaction/[transactionID]/[sku]?action=close PUT /transaction/[transactionID]?sku=[sku#]&action=close

Here is a good discussion on adding verbs to a REST call... http://looselyconnected.wordpress.com/2011/02/01/a-proposal-for-rest-and-verbs/