Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GenericCollectionEndpoint<TEntity, TElementEndpoint>

Endpoint for a collection of TEntitys addressable as TElementEndpoints.
Use CollectionEndpoint instead if you wish to use the default ElementEndpoint type.

Type parameters

  • TEntity

    The type of individual elements in the collection.

  • TElementEndpoint: ElementEndpoint<TEntity>

    The type of ElementEndpoint to provide for individual TEntitys.

Hierarchy

Implements

Index

Constructors

constructor

Properties

Readonly errorHandler

errorHandler: ErrorHandler

Handles errors in responses.

Readonly httpClient

httpClient: HttpClient

The HTTP client used to communicate with the remote resource.

Readonly linkExtractor

linkExtractor: LinkExtractor

Extracts links from responses.

Optional responseCache

responseCache: ResponseCache

A cached copy of the last response.

Readonly serializer

serializer: Serializer

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

Readonly uri

uri: URL

The HTTP URI of the remote resource.

Accessors

createAllAllowed

  • get createAllAllowed(): undefined | false | true
  • Shows whether the server has indicated that createAll is currently allowed. Uses cached data from last response.

    Returns undefined | false | true

    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.

createAllowed

  • get createAllowed(): undefined | false | true
  • Shows whether the server has indicated that create is currently allowed. Uses cached data from last response.

    Returns undefined | false | true

    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.

readAllAllowed

  • get readAllAllowed(): undefined | false | true
  • Shows whether the server has indicated that readAll is currently allowed. Uses cached data from last response.

    Returns undefined | false | true

    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.

setAllAllowed

  • get setAllAllowed(): undefined | false | true
  • Shows whether the server has indicated that setAll is currently allowed. Uses cached data from last response.

    Returns undefined | false | true

    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.

Methods

contains

  • contains(element: TEntity | string): Promise<boolean>

create

  • create(entity: TEntity, signal?: AbortSignal): Promise<TElementEndpoint | undefined>

createAll

  • createAll(entities: TEntity[], signal?: AbortSignal): Promise<void>

delete

  • delete(element: TEntity | string): Promise<void>

Protected deleteContent

  • deleteContent(signal?: AbortSignal): Promise<Response>

get

  • get(element: TEntity | string): TElementEndpoint
  • Returns an TElementEndpoint for a specific child element.

    Parameters

    • element: TEntity | string

      The ID identifying the entity or an entity to extract the ID from.

    Returns TElementEndpoint

Protected getContent

  • getContent(signal?: AbortSignal): Promise<string>

getLinkTemplate

  • getLinkTemplate(rel: string): string
  • 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

getLinks

  • getLinks(rel: string): { title?: undefined | string; uri: URL }[]
  • 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?: undefined | string; uri: URL }[]

Protected handle

  • handle(response: Response): Promise<void>
  • 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>

Protected handleCapabilities

  • handleCapabilities(response: Response): void

Protected isMethodAllowed

  • isMethodAllowed(method: HttpMethod): boolean | undefined
  • Shows whether the server has indicated that a specific HTTP method is currently allowed. Uses cached data from last response.

    Parameters

    • method: HttpMethod

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

    Returns boolean | undefined

    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.

Protected join

  • join(relativeUri: string): URL
  • 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

link

  • link(rel: string): 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

linkTemplate

  • linkTemplate(rel: string, variables: {}): 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: {}

      Variables for resolving the template.

      • [key: string]: any

    Returns URL

merge

  • merge(element: TEntity): Promise<undefined | TEntity>

Protected putContent

  • putContent(content: any, signal?: AbortSignal): Promise<Response>

readAll

  • readAll(signal?: AbortSignal): Promise<TEntity[]>

Protected send

  • send(method: HttpMethod, signal?: AbortSignal, headers?: HeadersInit, body?: BodyInit): Promise<Response>
  • 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>

set

  • set(element: TEntity): Promise<undefined | TEntity>

setAll

  • setAll(entities: TEntity[]): Promise<void>

setDefaultLink

  • setDefaultLink(rel: string, href?: undefined | string): void
  • 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: undefined | 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

setDefaultLinkTemplate

  • setDefaultLinkTemplate(rel: string, href?: undefined | string): 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
    • Optional href: undefined | string

    Returns void

Static Protected ensureTrailingSlash

  • ensureTrailingSlash(uri: URL | string): URL

Generated using TypeDoc