Endpoint for an individual resource.

Type Parameters

  • TEntity

    The type of entity the endpoint represents.

Hierarchy

Constructors

Properties

errorHandler: ErrorHandler

Handles errors in responses.

httpClient: HttpClient

The HTTP client used to communicate with the remote resource.

linkExtractor: LinkExtractor

Extracts links from responses.

responseCache?: ResponseCache

A cached copy of the last response.

serializer: Serializer

Controls the serialization of entities sent to and received from the server.

uri: URL

The HTTP URI of the remote resource.

Accessors

  • get deleteAllowed(): undefined | boolean
  • Shows whether the server has indicated that delete is currently allowed. Uses cached data from last response.

    Returns

    true if the method is allowed, false if the method is not allowed, undefined if no request has been sent yet or the server did not specify allowed methods.

    Returns undefined | boolean

  • get mergeAllowed(): undefined | boolean
  • Shows whether the server has indicated that merge is currently allowed. Uses cached data from last response.

    Returns

    true if the method is allowed, false if the method is not allowed, undefined if no request has been sent yet or the server did not specify allowed methods.

    Returns undefined | boolean

  • get setAllowed(): undefined | boolean
  • Shows whether the server has indicated that set is currently allowed. Uses cached data from last response.

    Returns

    true if the method is allowed, false if the method is not allowed, undefined if no request has been sent yet or the server did not specify allowed methods.

    Returns undefined | boolean

Methods

  • Retrieves a link template with a specific relation type. Uses cached data from last response. Prefer linkTemplate when possible.

    Throws

    NotFoundError: No link template with the specified rel could be found.

    Parameters

    • rel: string

      The relation type of the link template to look for.

    Returns string

  • Resolves all links with a specific relation type. Uses cached data from last response.

    Parameters

    • rel: string

      The relation type of the links to look for.

    Returns {
        title?: string;
        uri: URL;
    }[]

  • Handles various cross-cutting concerns regarding a response message such as discovering links and handling errors.

    Throws

    HttpError

    Parameters

    • response: Response

      The response to process.

    Returns Promise<void>

  • Shows whether the server has indicated that a specific HTTP method is currently allowed. Uses cached data from last response.

    Returns

    true if the method is allowed, false if the method is not allowed, undefined if no request has been sent yet or the server did not specify allowed methods.

    Parameters

    • method: HttpMethod

      The HTTP methods (e.g. GET, POST, ...) to check.

    Returns undefined | boolean

  • Resolves a relative URI using this endpoint's URI as the base.

    Parameters

    • relativeUri: string

      The relative URI to resolve. Prepend ./ to imply a trailing slash in the base URI even if it is missing there.

    Returns URL

  • Resolves a single link with a specific relation type. Uses cached data from last response.

    Throws

    NotFoundError: No link with the specified rel could be found.

    Parameters

    • rel: string

      The relation type of the link to look for.

    Returns URL

  • Resolves a link template with a specific relation type. Uses cached data from last response.

    Throws

    NotFoundError: No link template with the specified rel could be found.

    Parameters

    • rel: string

      The relation type of the link template to look for.

    • variables: {
          [key: string]: any;
      }

      Variables for resolving the template.

      • [key: string]: any

    Returns URL

  • Sends an HTTP request to this endpoint's URI. Handles various cross-cutting concerns regarding a response message such as discovering links and handling errors.

    Throws

    HttpError

    Parameters

    • method: HttpMethod

      The HTTP method to use.

    • Optional signal: AbortSignal

      Used to cancel the request.

    • Optional headers: HeadersInit

      The HTTP headers to set.

    • Optional body: BodyInit

      The body to send.

    Returns Promise<Response>

  • Registers one or more default links for a specific relation type. These links are used when no links with this relation type are provided by the server. This should only be called during initial setup of the endpoint.

    Parameters

    • rel: string

      The relation type of the link to add.

    • Optional href: string

      The href of the link relative to this endpoint's URI. Leave unspecified to remove any previous entries for the relation type.

    Returns void

  • Registers a default link template for a specific relation type. This template is used when no template with this relation type is provided by the server. This should only be called during initial setup of the endpoint.

    Parameters

    • rel: string

      The relation type of the link to add.

    • Optional href: string

      The templates href relative to this endpoint's URI. Leave unspecified to remove any previous entries for the relation type.

    Returns void

  • Reads the current state of the entity, applies a change to it and stores the result. Applies optimistic concurrency using automatic retries.

    Returns

    The TEntity as returned by the server, possibly with additional fields set. undefined if the server does not respond with a result entity.

    Throws

    ConcurrencyError: The maximum number of retries to perform for optimistic concurrency before giving up.

    Throws

    BadRequestError: BadRequest

    Throws

    AuthenticationError: Unauthorized

    Throws

    AuthorizationError: Forbidden

    Throws

    NotFoundError: NotFound or Gone

    Throws

    HttpError: Other non-success status code

    Parameters

    • updateAction: ((entity: TEntity) => void)

      A callback that takes the current state of the entity and applies the desired modifications.

        • (entity: TEntity): void
        • Parameters

          • entity: TEntity

          Returns void

    • maxRetries: number = 3

      The maximum number of retries to perform for optimistic concurrency before giving up.

    • Optional signal: AbortSignal

      Used to cancel the request.

    Returns Promise<undefined | TEntity>

Generated using TypeDoc