How to "lazy load" in a RESTful manner?

lazy-loading, rest, restful-url

Solution

Don't forget, hypermedia is your friend.

GET /hotel/{id}

HTTP/1.1 200 OK
<hotel Id="99">
  <a>aaa</a>
  <b>aaa</b>
  <biggieLink href="/Hotel/99/Biggie"/>
</hotel>

or you can even do

GET /hotel/{id}

HTTP/1.1 200 OK
<hotel Id="99">
  <a>aaa</a>
  <b>aaa</b>
  <biggieSynopsis href="/Hotel/99/Biggie">
    <title>Here is a a summary of biggie</title>
  </biggieSynopsis
</hotel>

Problem

Given this service to get information about a hotel: ``` > GET /hotel/{id} < HTTP/1.1 200 OK < <hotel> < <a>aaa</a> < <b>aaa</b> > <biggie>aaa....I am 300K</biggie > < </hotel> ``` Problem is that `biggie` is 300K and we don't want to return it with every response. What's the RESTful way to lazy load this value? Should we set up two resources: ``` > GET /hotel/{id} < HTTP/1.1 200 OK < <hotel> < <a>aaa</a> < <b>aaa</b> < </hotel> ``` and.. ``` > GET /hotel/{id}/biggie < HTTP/1.1 200 OK < <biggie> < <val>aaa....I am 300K</val> < </biggie> ``` And you only request `GET /hotel/{id}/biggie` when you really need that data? This would work.. although there is nothing special about `biggie` except that it's a large data set. I think it's nicer to keep everything at the `hotel` level as all the attributes are really just attributes of the `hotel`.

Original source