GET /hotel/{id} < HTTP/1.1 200 OK < < aaa ...">

How is the "lazy load" in RESTful?

Given this service, to get hotel information:

> GET /hotel/{id}

< HTTP/1.1 200 OK
< <hotel>
<   <a>aaa</a>
<   <b>aaa</b>
>   <biggie>aaa....I am 300K</biggie >
< </hotel>

The problem is that it biggieis 300K, and we do not want to return it with every answer. What is a RESTful way to lazily load this value?

Should we install 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 ask GET /hotel/{id}/biggiewhen you really need this data?

This will work ... although there is nothing special about biggie, except that it is a large dataset. I think it would be better to keep everything level hotel, since all attributes are actually just attributes hotel.

+3
source share
3 answers

, - .

GET /hotel/{id}

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

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>
+12

, , , ; , , .

+3

, . , :

  • (/{id}/a, /{id}/b, /{id}/biggie)
  • EXCEPT , .

1 2 , , 3 , , , .

(2 , , .)

+1

Source: https://habr.com/ru/post/1721106/


All Articles