Options
All
  • Public
  • Public/Protected
  • All
Menu

Class API<TGraph>

Base API class for all custom clients in this SDK. If you're building your own client, consider extending this class for consistency.

Type parameters

Hierarchy

Index

Constructors

constructor

  • new API(init: Init): API
  • Parameters

    • init: Init

    Returns API

Properties

Protected _cache

_cache: Storage

Resolver cache implementing Web Storage API.

Protected _console

_console: Consola

Shared Consola instance.

Protected _fetch

_fetch: Window["fetch"]

Custom Fetch API implementation for making authenticated requests.

Protected _path

_path: CurieChain

Path to this resource node as base URL followed by a list of curies.

base

base: URL

Bookmark URL for this API. This is where the tree traversal begins. We also use this URL as a base for relative paths.

cache

cache: Storage

Resolver cache implementing Web Storage API. Every resolved path will be stored here for future use. You can clear this cache by calling clear().

console

console: Consola

Consola instance. If you extend this class and add logging in your code, use this instead of native console.

storage

storage: Storage

Credentials storage implementing Web Storage API. Access tokens and other related info will be stored here. Clearing this storage will log you out.

Static AuthError

AuthError: AuthError = AuthError

Static Node

Node: Node = Node

Static ResolutionError

ResolutionError: ResolutionError = ResolutionError

Static Response

Response: Response = Response

Static WHATWGHeaders

WHATWGHeaders: { constructor: any; prototype: __type } = Headers

Polyfilled version of the built-in Headers class. If you need to pass an instance of Headers to .fetch(), use this class instead of the built-in one to avoid this issue.

Type declaration

  • constructor: function
    • new __type(init?: HeadersInit): __type
    • Parameters

      • Optional init: HeadersInit

      Returns __type

  • prototype: __type

Static WHATWGRequest

WHATWGRequest: { constructor: any; prototype: __type } = Request

Polyfilled version of the built-in Request class. If you need to pass an instance of Request to .fetch(), use this class instead of the built-in one to avoid this issue.

Type declaration

  • constructor: function
    • new __type(input: RequestInfo, init?: RequestInit): __type
    • Parameters

      • input: RequestInfo
      • Optional init: RequestInit

      Returns __type

  • prototype: __type

Static WHATWGResponse

WHATWGResponse: { constructor: any; prototype: __type; error: any; redirect: any } = Response

Polyfilled version of the built-in Response class. If you need to check the return value of .fetch(), use this class instead of the built-in one to avoid this issue.

Type declaration

  • constructor: function
    • new __type(body?: BodyInit | null, init?: ResponseInit): __type
    • Parameters

      • Optional body: BodyInit | null
      • Optional init: ResponseInit

      Returns __type

  • prototype: __type
  • error: function
    • Returns __type

  • redirect: function
    • redirect(url: string, status?: undefined | number): __type
    • Parameters

      • url: string
      • Optional status: undefined | number

      Returns __type

Static whatwgFetch

whatwgFetch: fetch = fetch

Polyfilled version of the built-in fetch function. If you need to call fetch() with poyfilled request, response or headers, use this function instead of the built-in one to avoid this issue.

Methods

Protected _resolve

  • _resolve(): Promise<URL>
  • Resolves resource URL from a curie chain. The first element in the path must be a URL.

    throws

    Throws {@link APIResolutionError} when once of the resources can't be reached.

    Returns Promise<URL>

    Resolved URL.

delete

  • delete(): Promise<Response<TGraph>>
  • Resolves the URL of this node and sends a DELETE request, removing this resource.

    Returns Promise<Response<TGraph>>

    Instance of {@link APIResponse} representing this resource.

fetch

  • fetch(...args: Parameters<Window["fetch"]>): ReturnType<Window["fetch"]>
  • Makes a raw and, if possible, authenticated request to the API. This method implements native Fetch API.

    Parameters

    • Rest ...args: Parameters<Window["fetch"]>

      Fetch API arguments (url and request parameters).

    Returns ReturnType<Window["fetch"]>

    Fetch API response.

follow

  • follow<C>(curie: C): Node<TGraph["links"][C]>
  • Resource path builder. Calling this method instructs our SDK to find the provided curie in this resource's links and navigate to its location on request.

    Type parameters

    • C: keyof TGraph["links"]

    Parameters

    • curie: C

      Curie to follow.

    Returns Node<TGraph["links"][C]>

    Instance of {@link APINode} representing the resource at curie location.

get

  • get(): Promise<Response<TGraph>>
  • get<Q>(query: Q): Promise<Response<TGraph, Q>>
  • Resolves the URL of this node and sends a GET request using provided parameters.

    Returns Promise<Response<TGraph>>

    Instance of {@link APIResponse} representing this resource.

  • Resolves the URL of this node and sends a GET request using provided parameters.

    Type parameters

    Parameters

    • query: Q

      Query parameters such as zoom, fields etc.

    Returns Promise<Response<TGraph, Q>>

    Instance of {@link APIResponse} representing this resource.

patch

  • patch(body?: Partial<TGraph["props"]>): Promise<Response<TGraph>>
  • Resolves the URL of this node and sends a PATCH request with provided properties, updating this resource.

    Parameters

    • Optional body: Partial<TGraph["props"]>

      Partial resource object.

    Returns Promise<Response<TGraph>>

    Instance of {@link APIResponse} representing this resource.

post

  • post(body?: TGraph["props"]): Promise<Response<TGraph>>
  • Resolves the URL of this node and sends a POST request with provided properties, creating a resource or triggering an action.

    Parameters

    • Optional body: TGraph["props"]

      Complete resource object.

    Returns Promise<Response<TGraph>>

    Instance of {@link APIResponse} representing this resource.

put

  • put(body?: TGraph["props"]): Promise<Response<TGraph>>
  • Resolves the URL of this node and sends a PUT request with provided properties, replacing the existing resource.

    Parameters

    • Optional body: TGraph["props"]

      Complete resource object.

    Returns Promise<Response<TGraph>>

    Instance of {@link APIResponse} representing this resource.

Object literals

Static v8n

v8n: object

classConstructor

classConstructor: any = v8n().schema({base: v8n().instanceOf(URL),cache: v8n().optional(storageV8N),fetch: v8n().optional(v8n().typeOf('function')),level: v8n().optional(v8n().integer()),storage: v8n().optional(storageV8N),})

Generated using TypeDoc