Support friendly aliases for link's rel attributes filled with namespaced URIs.
Reported by Marco Antonio Gonzalez Junior | July 12th, 2010 @ 04:16 PM
The use of an URI as the value for extension link relation types
is an IETF recommendation. Restfulie should support it. The
challenge is to provide a syntax sugar solution to it, keeping its
usage simple on the client side.
My suggestion is to use CURIEs and QName as identifiers for
extension relation types definition of the XML based formats. The
root element (or some inner node) must define the namespace(s) used
and the belonging rel type references it like below:
<?xml version="1.0"?>
<basket xmlns:acme="http://daffyduck.com/api/rels/" xmlns:hell="http://devil.com/api/rels" />
<link href="http://localhost:3000/baskets/1/payments" rel="payment" type="application/xml" />
<link href="http://localhost:3000/baskets/1" rel="self" type="application/xml" />
<link href="http://localhost:3000/baskets/1/make_disappear" rel="acme:freefallfromsomecanyon" />
<link href="http://localhost:3000/baskets/1/destroy" rel="hell:burn" type="application/xml" />
</basket>
This way it's still possible to provide more information on the http://devil.com/api/rels/burn URI.
On the client side, we would have something like:
resource.basket.links.hell.burn.post!
JSON draft proposal ("prefixes" or "@xmlns"):
{
"prefixes": {
"hell": "http://www.inferno.org/api/resources/rels/",
"heaven": "http://www.paradise.net/docs/rels/"
},
"link": {
"href": "http://kayaman.baurets.net/self/acts_as_nice_guy",
"rel": "heaven:acts_as_nice_guy",
"type": "application/json"
},
"link": {
"href": "http://kayaman.baurets.net/self/be_evil",
"rel": "hell:be_evil",
"type": "application/json"
}
}
Client side usage example:
kayaman.links.hell.be_evil.get! \m/
:-)
As stated on section 4.2 of (1): "Note that while extension relation types are required to be URIs, a serialization of links can specify that they are expressed in another form, as long as they can be converted to URIs."
References:
http://tools.ietf.org/html/draft-nottingham-http-link-header-10
http://internet-apps.blogspot.com/2005/10/curies-compact-uri-syntax...
http://www.w3.org/TR/curie
Deprecated ideas:
Server side:
link "http://mySystemOfSystems.com/rels/publish",
"http://related_resource.com"
Client side:
resource.links("http://mySystemOfSystems.com/rels/publish").post
resource.links_rel_base("http://mySystemOfSystems.com/rels").publish.post #something like that
Comments and changes to this ticket
-
Guilherme Silveira July 14th, 2010 @ 10:50 AM
Hello Marco,
Great idea, and we still need to support the URI based values, support could be:
Server side:
link "http://mySystemOfSystems.com/rels/publish", "http://related_resource.com"
link "hell:burn", "http://hell.com"
link "hell", "http://hell.com"Client side:
resource.links("http://mySystemOfSystems.com/rels/publish").post
resource.links("hell:burn").post
resource.links.hell.burn.post
resource.links.self.post
resource.links("self").postRegards
-
Marco Antonio Gonzalez Junior July 14th, 2010 @ 04:56 PM
For instance:
collection.link "http://kayaman.baurets.net/api/rels/register/", "http://kayaman.baurets.net:3000/items"
I have:
ruby-1.8.7-p299 > res = Restfulie.at("http://localhost:3000/items").get! ruby-1.8.7-p299 > res.items.links.baurets => #<Restfulie::Common::Converter::Xml::Link:0x7051c0 @options={"href"=>"nohref", "rel"=>:register}> ruby-1.8.7-p299 > res.items.links.baurets.register => #<Restfulie::Common::Converter::Xml::Link:0x6fd538 @options={"href"=>"http://kayaman.baurets.net:3000/items", "rel"=>"register", "type"=>"application/xml"}>There should be a way of blocking the 'baurets' method making http calls.
I still have to work on other syntax variations.
Thank you and regards,
marco
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »