Skip to main content

API Reference

This page documents all types, classes, and methods exported by Nitro Fetch.

Types & Interfaces

RequestConfig

Configuration for requests.

  • baseURL?: string — Base URL for requests
  • headers?: Record<string, string> — Custom headers
  • params?: Record<string, string | number | boolean> — Query params
  • timeout?: number — Timeout in ms
  • retry?: { count?: number; delay?: number; onRetry?: Function; shouldRetry?: Function; retryOnSuccess?: boolean } — Retry options

Response<T = any>

Response object returned from requests.

  • data: T — Response data
  • status: number — HTTP status code
  • statusText: string — Status text
  • headers: Record<string, string> — Response headers
  • config: RequestConfig — The config used

ApiEndpoint

Defines a named endpoint.

  • method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
  • path: string
  • config?: RequestConfig
  • data?: any
  • id?: string

InterceptorManager<V>

Manages interceptors for requests or responses.

  • use(onFulfilled, onRejected): number
  • eject(id: number): void
  • clear(): void

Class: NitroFetch

Constructor

new NitroFetch(config?: RequestConfig)

Instance Methods

  • get<T>(url: string, config?: RequestConfig): Promise<Response<T>>
  • post<T>(url: string, data?: any, config?: RequestConfig): Promise<Response<T>>
  • put<T>(url: string, data?: any, config?: RequestConfig): Promise<Response<T>>
  • delete<T>(url: string, config?: RequestConfig): Promise<Response<T>>
  • patch<T>(url: string, data?: any, config?: RequestConfig): Promise<Response<T>>
  • registerEndpoint(name: string, endpoint: ApiEndpoint): void
  • registerEndpoints(endpoints: Record<string, ApiEndpoint>): void
  • call<T>(name: string, data?: any, config?: RequestConfig): Promise<Response<T>>

Properties

  • interceptors.request — Request interceptors manager
  • interceptors.response — Response interceptors manager

Factory

create(config?: RequestConfig): NitroFetch

Creates a new NitroFetch instance.


For more details, see the source code or previous sections for usage examples.