For all the REST fans out there, I have two questions.
Usually when we think of RESTful urls, we think in terms of rather simple struct-like objects. The canonical example is using ActiveResource to create person objects:
POST /people <person> <first_name>Jeff</first_name> <last_name>Cohen</last_name> </person>
We expect to get back a 201 response with the url to the newly-created resource, like /people/47. If I GET /people/47, I should see the exact same data as when I created it.
My first question is, what if this is not a symmetrical operation? For example, let's say I want to transmit a pizza order:
POST /orders <order> <name>Jeff</name> <phone>555-555-1212</phone> <combo>3</combo> </order>
Here I'm ordering combo #3, which is a actually a large pepperoni, a 6- pack of root beer, and a slice of tiramisu. The server responds with a 201 to /orders/342.
But if I do a GET /orders/342, I might see this:
<order> <id>342</id> <name>Jeff</name> <phone>555-555-1212</phone> <items> <item> <id>1</id> <desc>18" Pepperoni</desc> <qty>1</qty> </item> <item> <id>2</id> <desc>Root Beer</desc> <qty>6</qty> </item> <item> <id>1</id> <desc>Tiramisu</desc> <qty>1</qty> </item> </items> </order>
Is this kind of thing acceptable in the REST world? I hope so, because having the client create each step of the hierarchy would be a pain (first create an empty order, then create each line item, etc.)
My second question is, how would I create the pizza order using ActiveResource? In other words, do I need to worry that the attributes that I use for the create action are not the same as the attributes I'll be receiving?