Java Reference
In-Depth Information
<state>
<state>
MA
</state>
</state>
<zip>
<zip>
02115
</zip>
</zip>
</customer>
</customer>
<line-items>
<line-items>
<line-item
<line-item id=
"144"
>
<product
<product id=
"543"
>
<link
<link rel=
"self"
href=
"http://example.com/products/543"
//>
<name>
<name>
iPhone
</name>
</name>
<cost>
<cost>
$199.99
</cost>
</cost>
</product>
</product>
<quantity>
<quantity>
1
</quantity>
</quantity>
</line-item>
</line-items>
</line-item>
</line-items>
</order>
</order>
The
Order
data format has the top-level elements of
total
and
date
that specify the total
cost of the order and the date the
Order
was made.
Order
is a great example of data compos-
ition, as it includes
Customer
and
Product
information. This is where the
link
element be-
comes particularly useful. If the client is interested in interacting with a
Customer
or
Product
that makes up the
Order
, it has the URI needed to interact with one of these re-
sources.
Create Format
When we are creating new
Orders
,
Customers
, or
Products
, it doesn't make a lot of sense
to include an
id
attribute and
link
element with our XML document. The server will gener-
ate IDs when it inserts our new object into a database. We also don't know the URI of a new
object because the server also generates this. So, the XML for creating a new
Product
would
look something like this:
<product>
<product>
<name>
<name>
iPhone
</name>
</name>
<cost>
<cost>
$199.99
</cost>
</cost>
</product>
Orders
and
Customers
would follow the same pattern and leave out the
id
attribute and
link
element.
Assigning HTTP Methods
The final thing we have to do is decide which HTTP methods will be exposed for each of our
resources and what these methods will do. It is crucial that we do not assign functionality to
an HTTP method that supersedes the specification-defined boundaries of that method. For