users@jersey.java.net

RESTful URLs

From: Markus Karg <karg_at_quipsy.de>
Date: Wed, 20 May 2009 11:02:06 +0200

Hi Everybody,

 

here is another philosophic question.

 

My database stores parts. Each part has zero to infinite
characteristics. So I have two tables N:M with a foreign key and the
same a JPA entities ontop of it. Also I created a JAX-RS resource for
the parts with a subresource for the characteristics. As you can see,
the technic is not the problem.

 

My questions is: What is the optimal URL schema for this?

 

One can image a lot of fancy things, each with pros and cons. But as the
sample is just trivial, there should be a single, trivial answer. And,
as the service shall be unaware of the potential third party client
accessing it, it should be possible to do complex things without knowing
them before (just as the database server can execute any SQL without
knowing it before).

 

Some ideas to address a particular characteristic which all are working
but might not be optimal:

 

(1) http://myhost/systemroot/parts/{PartID} /characteristics/{ChID}

 

(2) http://myhost/systemroot/parts;ID={PartID}/characteristics;ID={ChID}

 

(3) http://myhost/systemroot/{ChID}
<http://myhost/systemroot/%7bChID%7d> with
Accept=application/characteristic+xml and ChID being unique.

 

(4) http://myhost/systemroot?type=characteristic;id={ChID}
<http://myhost/systemroot?type=characteristic;id=%7bChID%7d> and ChID
being unique.

 

(5) http://myhost/systemroot/{ChID}
<http://myhost/systemroot/%7bChID%7d> and ChID beeing globally unique
(i. e. parts and characteristics share one address room)

 

(6) ...not addressing the characteristic at all but contain all
characteristic directly in the part's XML

 

Obviously there are lots of solutions, but I could imagine that after
years of RESTfulness, the experts might have identified one that is
optimal. But which one is it? And, the problem gets more complex if you
don't want to give the ID but query by a different attribute like
"displayName" -- how to make up a URL which could serve both cases...?

 

Any comments welcome!

 

Regards

Markus