NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
ido.ran
Joined: 12 Mar 2009 Posts: 13
|
Posted: Sat Mar 28, 2009 2:14 pm Post subject: REST uri attribute |
|
|
Hello,
I'm build a RESTful Web Service using NetBeans.
I've been looking at sample code and RESTful patterns template and I've notice that the *Converter classes all have an attribute name uri.
As I understand (and I maybe wrong) the uri reference to the location of the resource represented.
For example, if I have the following hierarchy of resources:
Customers/{custid}/Orders/{orderid}
This url maps to the following resources:
Customers / {custid} / Orders / {orderid}
| | | |
| | | |
Customer Customr Order Order
Collection Resource Collection Resource
Resource Resource
This design confirms to container-item pattern of NetBeans RESTful web services.
The thing is that another way to get all the orders in the system is simply to GET the url /Orders which also return OrderCollectionResource of all the orders in the system (not just the orders of a specific customer).
Now, each resource has a converter class which map the object structure to xml (or json) string.
Each converter has uri attribute and also each converter get expand-level parameter which indicate how deep the converter should continue converting sub-resources.
The problem is as following.
When we ask the the url /Customers/123/Orders we will get collection of orders of customer number 123.
For example we might get the following response content:
<orders>
<order uri="http://myapp.com/Cutsomers/123/Orders/A">
<item>ItemX</item>
</order>
<order uri="http://myapp.com/Customers/123/Orders/B">
<item>ItemY</item>
</order>
</orders>
As you can see, the uri does not map to the resource itself, it map to the resource in the context in which is was requested.
Another possible way it to map the uri to the resource itself, as follows:
<orders>
<order uri="http://myapp.com/Orders/A">
<item>ItemX</item>
</order>
<order uri="http://myapp.com/Orders/B">
<item>ItemY</item>
</order>
</orders>
Now, if we ask for a customer and would like to get the list of all the uri of the orders it has, not the order content itself, we will be able to later use the uri to ask for the content of each order.
for example:
<customer>
<orders>
<order uri="http://myapp.com/Orders/A" />
<order uri="http://myapp.com/Orders/B" />
</orders>
</customer>
What do you think? Is it better to have uri with the context in which it was requrest, but makes it hard to continue navigate to the content of it, or ot have the uri refer to the real resources?
Thank you,
Ido. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|