How do you imagine the thin and bold versions of a RESTful resource?

How would you model a resource that can have two different representations. For example, a single view may be subtle, with most of the associated resources available via links. Another view might be "fat," in which most of the resources associated with it are embedded. The idea is that some customers are not averse to making many calls to view related resources, but others want to receive data right away.

Consider the resource of the film associated with the director, actors, etc. Perhaps the thin version has only the name of the film, but to obtain data for the director, the list of actors, etc. you need to make additional requests through the built-in links to them. Perhaps the thick version contains the entire film embedded inside, including the director’s data, data for different actors, etc.

How should this be modeled?

I see several options:

  • these two views really represent two different resources and require different URIs.
  • these two views are actually the same resource, and you can choose between two views through custom media types, for example application/vnd.movie.thin+jsonand application/vnd.movie.fat+json.
  • these two views are actually the same resource, and the choice of different views must be done using query parameters (for example, /movies/1?view=thin).
  • Something else...

What do you think is the right approach to this API?

+4
source share
3 answers

You can use a preference header with a minimum return parameter.

+3
source

The REST filigree dissertation tells you about the resource interface that you need to bind your IRIs to resources that are collections of entities. (This is different from SOAP because there you usually associate your IRIs with operations.)

Darrel Miller, , - IRI, API.

, , :

  • , IRI. /movies/1?view=thin /movies/1/view:thin .
    :

    • RDF a rdf:type of rdf:Property rdfs:Resource, REST .
    • IRI , /movies/1/title, , , .
    • map reduce, entites: /movies/recent .. , , . , : /movies/recent/title, .

    :

    • RDF rdf:type of rdfs:Resource, , , REST -.
    • , , ( )...
  • , - , IRI. . GET , HTTP , , , HTTP. cookie, . . content-type MIME, , , MIME, , . content-type MIME Doug Moscrop . prefer header return-minimal Darrel Miller . range , .
    :

    • , , RESTful.

    :

    • HTTP , .
    • , , , , , .

: , .

Darrel Miller IRI REST.

, IRI , . IRI , HATEOAS, , IRI. , IRI, IRI, . -, , -... REST , , . RDF, , schema.org, microdata, iana .. ( vocab)...
, IRI REST, . IRIS REST, IRI, - IRI, IRI , , , .....

+1

I prefer to use Content-Type for this. You can also use options:

application/vnd.myapp; profile=light

+1
source

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


All Articles