In the RESTful world, there is a discussion about whether to return an id or a URL. Some RESTful Web Services returns identifiers while others complete URL for resources. But which one to use? Ok, suppose that our Web Service returns JSON encoded data and that a User can takes several books on loan.
Now, suppose a
GET /user/1/books returns book ids on loan for user 1 as
So, the discussion is whether to return
After reading several articles and blogs, I’ve found that numerous developers prefer the second one because the baseurl can be changed without affecting the application. However, I completely disagree with this because even with the first one, the base url can be made dynamic. Also, with the second one, unnecessary data are sent back with is cumbersome.
But, I prefer a different solution. Suppose you have a REST interface running at http://example.com/v1, I find it better to expose the base URL itself. Say that a
GET http://example.com/baseURL returns
http://example.com/v1. Then, you can just get the base URL once that application first start up, and put it in a global variable so that it can be accessed everywhere throughout the application.
This is a solution which I though on the fly after reading several posts advising the use of complete URL. It may be wrong but one thing for sure, returning completing URL for a resource may good but not the best.