Class for making requests to Publit Core and similar API:s

const works = await new PublitApiRequest<Work>("works")
.where("title", "LIKE", "lord of the")
.with("contributors")
.index()

Type Parameters

  • T

Constructors

Properties

Options passed via the constructor

requestInit: RequestInit

Options passed to the actual fetch request

response?: Response

Fetch response object, available after the request is done

defaultOptions: ApiRequestOptions = ...

Options used for all requests, unless overridden individually

Accessors

Methods

  • Deletes a single resource on the specified endpoint

    Parameters

    • id: string

    Returns Promise<T>

  • Allows for filtering through relations

    request.filter('authors', 'name', 'LIKE', 'John')
    request.filter('authors', 'name', 'LIKE', ['John', 'Doe'])
    request.filter('authors', 'name', 'LIKE', 'John', 'AND')
    request.filter('authors', 'name', 'EQUAL', 'John', 'AND')

    Type Parameters

    • R extends string | number | symbol

    Parameters

    • relation: R

      The relation to filter on

    • Optionalattribute: string

      The attribute to filter on

    • Optionaloperator: Operator

      Operator to use for filtering

    • Optionalvalue: string | string[]

      Value to filter on

    • combinator: Combinator = 'OR'

      Combinator for any further has filters

    Returns PublitApiRequest<T>

  • Limit the number of results returned

    Usage:

    request.limit(10)
    request.limit(10, 20)

    Parameters

    • limit: number

      Number of result to return

    • Optionaloffset: number

      Starting offset

    Returns PublitApiRequest<T>

  • Order results by a given attribute

    request.orderBy('name', 'ASC')
    request.orderBy('name', 'DESC')

    Parameters

    • attribute: keyof T

      The attribute to order by

    • Optionaldirection: "ASC" | "DESC"

      Direction to order by

    Returns PublitApiRequest<T>

  • Retrieves a single resource from the specified endpoint

    Parameters

    • Optionalid: string

    Returns Promise<T>

  • Creates a new resource on the specified endpoint

    Type Parameters

    • StoreT = T

    Parameters

    • Optionalpayload: unknown

    Returns Promise<StoreT>

  • Updates a single resource on the specified endpoint

    Parameters

    • id: string
    • Optionalpayload: unknown

    Returns Promise<T>

  • Allows for filtering on attributes on the requested object

    request.where('name', 'LIKE', 'John')
    request.where('name', 'LIKE', ['John', 'Doe'])
    request.where('name', 'LIKE', 'John', 'AND')
    request.where('name', 'EQUAL', 'John', 'AND')

    Parameters

    • attribute: string

      The attribute to filter on

    • operator: Operator

      Operator to use for filtering

    • value: string | string[]

      Value to filter on

    • combinator: Combinator = 'OR'

      Combinator for any further where filters

    Returns PublitApiRequest<T>