Options
All
  • Public
  • Public/Protected
  • All
Menu

@paquitosoft/fetcher

Fetcher is a small library on top of native fetch API to make it easier working with network requests.

Index

Type Aliases

AfterMiddleware<T>: ((serverData: T, context: { response: Response }) => T)

Type Parameters

  • T = any

Type declaration

    • (serverData: T, context: { response: Response }): T
    • Parameters

      • serverData: T
      • context: { response: Response }
        • response: Response

      Returns T

BeforeMiddleware: ((options: RequestMiddlewareOptions) => BeforeMiddlewareResult | undefined | null)

Type declaration

BeforeMiddlewareResult: { body?: unknown; fetchOptions?: RequestInit; ttl?: number; url?: string }

Type declaration

  • Optional body?: unknown
  • Optional fetchOptions?: RequestInit
  • Optional ttl?: number
  • Optional url?: string
CacheManagerSetterOptions: { ttl?: number }

Type declaration

  • Optional ttl?: number
HTTPMethod: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "CONNECT" | "TRACE"
RequestMiddlewareOptions: { body?: unknown; cache?: CacheManager; fetchOptions: RequestInit; method: HTTPMethod; ttl?: number; url: string }

Type declaration

  • Optional body?: unknown
  • Optional cache?: CacheManager
  • fetchOptions: RequestInit
  • method: HTTPMethod
  • Optional ttl?: number
  • url: string
RequestOptions: { fetchOptions?: RequestInit; ttl?: number }

Represents the options you may use when using the different request types.

param ttl

Time to live in seconds

param fetchOptions

The options to pass to the native fetch API

Type declaration

  • Optional fetchOptions?: RequestInit
  • Optional ttl?: number

Functions

  • addMiddleware(type: "after" | "before", middleware: Middleware): void
  • Add a middleware to be executed before or after every request.

    Parameters

    • type: "after" | "before"

      'before' or 'after'

    • middleware: Middleware

      Middleware to add

    Returns void

    void

  • del<T>(url: string, options?: RequestOptions & { body?: string | object }): Promise<T>
  • Send a DELETE request to the given URL.

    Type Parameters

    • T

      Type of the data to return

    Parameters

    • url: string
    • Optional options: RequestOptions & { body?: string | object }

    Returns Promise<T>

    Fetched data (response body)

  • Send a GET request to the given URL.

    Type Parameters

    • T

      Type of the data to return

    Parameters

    Returns Promise<T>

    Fetched data (response body)

  • post<T>(url: string, body: string | object, options?: RequestOptions): Promise<T>
  • Send a POST request to the given URL.

    Type Parameters

    • T

      Type of the data to return

    Parameters

    Returns Promise<T>

    Fetched data (response body)

  • put<T>(url: string, body: string | object, options?: RequestOptions): Promise<T>
  • Send a PUT request to the given URL.

    Type Parameters

    • T

      Type of the data to return

    Parameters

    Returns Promise<T>

    Fetched data (response body)

  • Remove a middleware from the list of middlewares. (it will look for it both in 'before' and 'after' middlewares)

    Parameters

    Returns Middleware | undefined

    removed middleware if it really existed

  • Send a request to the given URL using the given HTTP method.

    Type Parameters

    • T

      Type of the data to return

    Parameters

    Returns Promise<T>

    Fetched data (response body)

Generated using TypeDoc