REST Resource Types
Let's discuss the two types of REST resources: a single entity, known as a singular resource, and a combined list of items, known as a collection resource.
Singular Resources
- Use a hierarchical structure that includes child resources.
- Includes a
links
property that supports HATEOAS, which is an important constraint of the resources. This property is used to define links to related resources.
The following table describes the properties of a link object.
Property | Description |
---|---|
|
Defines the relationship to the target resource. Types of links include:
|
|
A URL for accessing the resource. |
|
A unique identifier for the link. |
|
Indicates the type of target resource that the link references. Valid values are |
Collection Resource
- Extend a singular resource using the
links
property. - Support requests in parts so that you can implement a paginated response. The client can get a part of the collection in one request, followed by multiple subsequent requests for the next or previous part. To support this navigation, the links section can include links to the previous page and next page.
- Function either as a root resource or a subresource.
- Include an array of singular resources of the same type.
- Allow the client to use the
orderBy
command to specify an order for the items returned. Otherwise, the order can't be determined.
The following table lists querying and paging parameters for a collection resource.
Parameter | Description |
---|---|
|
An array of items in the collection. Each item is a singular resource. |
|
A Boolean value that indicates whether there are more items to be retrieved. Valid values:
|
|
An integer value that specifies the total number of resource instances in the response. It includes the instances in the current response and the instances yet to be retrieved. |
|
An integer value that specifies the paging size that the server uses for a client request. The default value is 25. The server might override this value to improve application performance. |
|
An integer value the specifies the number of items in the paging response. This value matches the value in the |
|
An integer value that specifies the index of the first item to be returned. The default value is 0. For example:
|