I have just read the book REST in Practice: Hypermedia and Systems Architecture and am now trying out some of the ideas but cannot figure out whether to use absolute or relative URIs in my response documents.
I would prefer the abosulte URIs but can see that there will be a problem when going to production, where the server infrastructure with load balancer, apache rewrites, and Tomcat servers would overwrite the original URI and mess up my URI-generate mechanism, information such as the scheme and the context path will be rewritten or lost when it hits the Java code, and the URIs will not be correct from the clients point of view.
I then get tempted to just use relative URIs but is that a good idea or a wrong turn to take?
The book is persistent in using absolute URIs, but I cannot find any mentions regarding this. Martin Fowler wrote about Richardson Maturity Model and he's using relative URIs.
What do you think? pros/cons?
I use relative URIs in many of my representations. My representations tend to be xml based so I make sure I include an xml:base attribute so it is clear where the relative URI is based.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With