Options
All
  • Public
  • Public/Protected
  • All
Menu

api-link

Index

Type aliases

IApiClass

IApiClass: {}

Generated API Class

Type declaration

IArgsValueMapper

IArgsValueMapper: (methodName: string, argName: string, value: any) => any

Hook for overriding argument values

param

API method name

param

API argument name

param

API argument value

returns

mapped API argument value

Type declaration

    • (methodName: string, argName: string, value: any): any
    • Parameters

      • methodName: string
      • argName: string
      • value: any

      Returns any

IDefaultArgsMapper

IDefaultArgsMapper: (requestMethod: string, methodName: string) => IMethodArgs

Hook for injecting default arguments for API calls

param

request method (GET, POST, PUT, DELETE)

param

API method name

returns

default arguments

Type declaration

    • (requestMethod: string, methodName: string): IMethodArgs
    • Parameters

      • requestMethod: string
      • methodName: string

      Returns IMethodArgs

IDeliveryMapper

IDeliveryMapper: (requestMethod: string, methodName: string, argName: string, value: any) => EArgDeliveryType

Hook for overriding logic of how delivery type is applied

param

request method (GET, POST, PUT, DELETE)

param

API method name

param

API argument name

param

API argument value

returns

resolved delivery type

Type declaration

    • (requestMethod: string, methodName: string, argName: string, value: any): EArgDeliveryType
    • Parameters

      • requestMethod: string
      • methodName: string
      • argName: string
      • value: any

      Returns EArgDeliveryType

IMethodFormatter

IMethodFormatter: (methodName: string) => string

Hook for overriding how method names are formatted

param

API method name before altering

results

altered method name

Type declaration

    • (methodName: string): string
    • Parameters

      • methodName: string

      Returns string

IMethodMapper

IMethodMapper: (methodName: string, args: IMethodArgs) => { methodName: string; requestMethod: string }

Hook for overriding request and API methods

param

API method name

param

object of arguments passed to API Link method

returns

mapped request and API methods

Type declaration

    • (methodName: string, args: IMethodArgs): { methodName: string; requestMethod: string }
    • Parameters

      Returns { methodName: string; requestMethod: string }

      • methodName: string

        API method name

      • requestMethod: string

        Request method (GET, POST, PUT, DELETE)

IOverrideFetchArgs

IOverrideFetchArgs: (url: string, requestInit: RequestInit) => { requestInit: RequestInit; url: string }

Hook for overriding fetch arguments right before execution

param

URL to be used for browser fetch API

param

additional options for browser fetch API

returns

mapped arguments for browser fetch API

Type declaration

    • (url: string, requestInit: RequestInit): { requestInit: RequestInit; url: string }
    • Parameters

      • url: string
      • requestInit: RequestInit

      Returns { requestInit: RequestInit; url: string }

      • requestInit: RequestInit
      • url: string

IRequestBodyMapper

IRequestBodyMapper: (args: {}) => string

Hook for overriding how arguments are serialized for body

param

API arguments for body before serialization

returns

serialized body

Type declaration

    • (args: {}): string
    • Parameters

      • args: {}
        • [name: string]: any

      Returns string

IRequestQueryMapper

IRequestQueryMapper: (args: {}, getQuery: typeof getQueryMethod) => string

Hook for overriding how query argument are serialized for URL

param

API query arguments before preparing a query string

param

helper method for generating default query string

returns

prepared query

Type declaration

    • (args: {}, getQuery: typeof getQueryMethod): string
    • Parameters

      • args: {}
        • [name: string]: any
      • getQuery: typeof getQueryMethod

      Returns string

IResponseMapper

IResponseMapper: (response: Response) => Promise<any>

Hook for overriding how response is parsed

param

browser fetch API response

returns

promise of mapped response

Type declaration

    • (response: Response): Promise<any>
    • Parameters

      • response: Response

      Returns Promise<any>

Variables

Const ALLOWED_REQUEST_METHODS

ALLOWED_REQUEST_METHODS: string[] = ['GET', 'POST', 'PUT', 'DELETE']

Supported request methods

Const Api

Api: {} = (class {protected _proxy: anyconstructor(config: IApiConfig = {}) {config = {baseUrl: '',multipleMethodArgs: false,defaultArgsMapper: () => ({}),argsDeliveryMapper: requestMethod =>requestMethod === 'GET'? EArgDeliveryType.QUERY: EArgDeliveryType.BODY,argsValueMapper: (...[, , value]) => value,requestMethodMapper: resolveMethodByConvention,apiMethodFormatter: formatMethod,requestBodyMapper: body => JSON.stringify(body),requestQueryMapper: query => getQuery(query),responseMapper: response => response.json(),overrideFetchArgs: (url, requestInit) => ({url,requestInit,}),...config,fetchConfig: {requestInit: {method: null,headers: {'Content-Type': 'application/json'},...(config.fetchConfig?.requestInit ?? {}),},},}this._proxy = createProxy.call(this, config, true)return createProxy.call(this, config)}} as any) as IApiClass

Api Link class

Type declaration

Const DEFAULT_DETECTED_REQUEST_METHOD

DEFAULT_DETECTED_REQUEST_METHOD: "POST" = "POST"

Default request method

Functions

Const cloneConfig

  • cloneConfig(config: IApiConfig): { fetchConfig: object }
  • Parameters

    Returns { fetchConfig: object }

    • fetchConfig: object
      • requestInit: object

Const createProxy

  • createProxy(config: IApiConfig, ignoreOverrides?: boolean): any

Const formatMethod

  • formatMethod(methodName: string): string
  • Formats method name before using it

    Parameters

    • methodName: string

      initial method name

    Returns string

    formatted method name

Const getArgsByDeliveryType

Const getQuery

  • Serializes arguments to a query which can then be added to URL

    Parameters

    Returns string

    query to be appended to URL

Const mapValues

Const resolveMethodByConvention

  • resolveMethodByConvention(methodName: string): { methodName: string; requestMethod: string }
  • Resolves request and API methods based on default API Link convention

    Parameters

    • methodName: string

      method name as it was written by API consumer

    Returns { methodName: string; requestMethod: string }

    mapped request and API methods

    • methodName: string
    • requestMethod: string

Generated using TypeDoc