Skip to content

HalDocument

Mihael Safaric edited this page Mar 13, 2019 · 14 revisions

When fetching a list of resources, some other data may be retrieved in the response (ie. pagination information).

Note: HalDocument is opinionated. If behaviours of HalDocument are not fully suitable for your case, you can create an additional class which extends HalDocument and then use that class instead of pure HalDocument class. A custom HalDocument class can be set on a model level (see ModelConfig) or on a datastore level (see DatastoreConfig).

When an instance of HalDocument is created, it gets three parameters in the constructor:

  • rawResponse: RawHalResource

    • HAL formatted object fetched from the server
  • modelClass: ModelConstructor<T>

    • model class which will be used for creating models
  • datastore: DatastoreService

Once instantiated, HalDocument parses rawResponse and generates models and pagination properties.

Properties

  • models: Array<Model>

    • instances of modelClass class which is passed through the constructor
  • pagination: Pagination

    • instance of Pagination class
    • TODO make a way to override Pagination class on DatastoreService level, and on ModelService level
  • hasEmbeddedItems: boolean

    • returns true if list items were included in the first HTTP request
  • itemLinks: Array<RawHalLink>

    • returns links to the specific list items