restrestful-architectureapi-designlaminas-api-tools

Should rest resource have same structure in collection


I found question about subset of REST when display resource by GET /task/ID and as row in collection GET /task. REST - Resource and Collection Representations

I'm using Apigility.

I know REST is not official, but want to hold as strict as could with overall best practice/standard.

Can i have others fields in collection and resource. Of cource part will be the same, but for collection i need some extra information for filtering and in resource there is now need for them.

Is this will breaking in any way some rules?


Solution

  • It is not uncommon to return partial representations of resources in a REST collection response, while the full representation is returned when the singleton endpoint is requested.

    Read for example here (one of the first links I found with this search on Google, there are many more).

    Getting a collection

    Getting a collection, like "members" may return
    1) the entire list of resources as a list of links,
    2) partial representations of each resource, or
    3) full representations of all the resources in the collection.

    So it is not uncommon that a resource representation in a collection differs from the singleton representation, but I would say you would rather have less then more data.

    What particular fields were you thinking about adding to the response in your collection? Can you give an example?