Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Constructors

constructor

  • new JsonApi(args?: JsonApiArguments): JsonApi
  • Constructor to inject the dependencies

    Parameters

    • Optional args: JsonApiArguments

    Returns JsonApi

Properties

Protected _axios

_axios: AxiosInstance

Holds the axios instance we use for our requests

Protected _guid

_guid: any

A unique id for this api instance

Accessors

axios

  • get axios(): AxiosInstance
  • Returns the axios instance we use internally

    Returns AxiosInstance

Methods

Protected deserializeResponse

  • deserializeResponse(response: PlainObject<any>): Promise<JsonApiResponse>
  • Internal helper which receives the raw result from axios and de-serializes the json api structure into a more speaking javascript object

    Parameters

    • response: PlainObject<any>

    Returns Promise<JsonApiResponse>

Protected formatQuery

  • formatQuery(query?: PlainObject<any> | JsonApiGetQuery, prefix?: string): string
  • Internal helper which formats the get query object into the correct query string

    Parameters

    • Optional query: PlainObject<any> | JsonApiGetQuery
    • Optional prefix: string

    Returns string

get

  • get(resourceType: string, query?: JsonApiGetQuery, debounceLimit?: number): Promise<JsonApiStateList>
  • Requests a resource collection from the server

    deprecated

    will be removed in v4.0 - use getCollection() instead.

    Parameters

    • resourceType: string

      The resource type to request from the server

    • Optional query: JsonApiGetQuery

      An optional query to use when requesting the resources

    • Optional debounceLimit: number

      Can be used to debounce multiple, subsequent requests for a certain number of milli-seconds, before they should be actually submitted to the server. Can be used to avoid multiple request for text inputs or similar occurrences.

    Returns Promise<JsonApiStateList>

getAdditional

  • getAdditional(resourceType: string, uriFragment: string, query?: JsonApiGetQuery, debounceLimit?: number): Promise<any>
  • Finds the data for "additional routes" that are registered on a certain resource type.

    Parameters

    • resourceType: string

      The type of entity to resolve the data for

    • uriFragment: string

      The additional uri fragment that should be added after the resource type in the uri

    • Optional query: JsonApiGetQuery

      An optional query to use when requesting the resource

    • Optional debounceLimit: number

      Can be used to debounce multiple, subsequent requests for a certain number of milli-seconds, before they should be actually submitted to the server. Can be used to avoid multiple request for text inputs or similar occurrences.

    Returns Promise<any>

getCollection

  • getCollection(resourceType: string, query?: JsonApiGetQuery, debounceLimit?: number): Promise<Collection>
  • Requests a resource collection from the server

    Parameters

    • resourceType: string

      The resource type to request from the server

    • Optional query: JsonApiGetQuery

      An optional query to use when requesting the resources

    • Optional debounceLimit: number

      Can be used to debounce multiple, subsequent requests for a certain number of milli-seconds, before they should be actually submitted to the server. Can be used to avoid multiple request for text inputs or similar occurrences.

    Returns Promise<Collection>

getResource

  • getResource(resourceType: string, id: string | number, query?: JsonApiGetQuery, debounceLimit?: number): Promise<Resource>
  • Requests a single resource item from the server

    Parameters

    • resourceType: string

      The resource type to request from the server

    • id: string | number

      The id of the entity to request from the server. Set this to NULL if your endpoint does not require a unique id for requesting a single entity

    • Optional query: JsonApiGetQuery

      An optional query to use when requesting the resource

    • Optional debounceLimit: number

      Can be used to debounce multiple, subsequent requests for a certain number of milli-seconds, before they should be actually submitted to the server. Can be used to avoid multiple request for text inputs or similar occurrences.

    Returns Promise<Resource>

getSingle

  • getSingle(resourceType: string, id: string | number, query?: JsonApiGetQuery, debounceLimit?: number): Promise<JsonApiState>
  • Requests a single resource entity from the server

    deprecated

    will be removed in v4.0 - use getResource() instead.

    Parameters

    • resourceType: string

      The resource type to request from the server

    • id: string | number

      The id of the entity to request from the server. Set this to NULL if your endpoint does not require a unique id for requesting a single entity

    • Optional query: JsonApiGetQuery

      An optional query to use when requesting the resource

    • Optional debounceLimit: number

      Can be used to debounce multiple, subsequent requests for a certain number of milli-seconds, before they should be actually submitted to the server. Can be used to avoid multiple request for text inputs or similar occurrences

    Returns Promise<JsonApiState>

Protected handleAxiosResponse

  • handleAxiosResponse(response: AxiosResponse<any>): Promise<JsonApiStateList | JsonApiState>
  • Internal response handler to create

    Parameters

    • response: AxiosResponse<any>

    Returns Promise<JsonApiStateList | JsonApiState>

makeQueryString

  • makeQueryString(query?: JsonApiGetQuery): string
  • Can be used to format a query object into a url conform query string

    Parameters

    • Optional query: JsonApiGetQuery

    Returns string

makeResourceOrCollection

  • makeResourceOrCollection(data: PlainObject<any> | JsonApiResponse | JsonApiElementInterface): Promise<Collection | Resource>
  • Receives a raw json api response (presumably from an ajax request) and converts it either into a json api state, or a state list object, depending on the content

    Parameters

    • data: PlainObject<any> | JsonApiResponse | JsonApiElementInterface

      The data to convert into either a resource or a collection

    Returns Promise<Collection | Resource>

makeStateOrStateList

  • makeStateOrStateList(response: PlainObject<any> | JsonApiResponse): Promise<JsonApiStateList | JsonApiState>
  • Receives a raw json api response (presumably from an ajax request) and converts it either into a json api state, or a state list object, depending on the content

    deprecated

    Will be removed in v4.0 use makeResourceOrCollection() instead!

    Parameters

    • response: PlainObject<any> | JsonApiResponse

    Returns Promise<JsonApiStateList | JsonApiState>

Generated using TypeDoc