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 requestsheaders?: Record<string, string>
— Custom headersparams?: Record<string, string | number | boolean>
— Query paramstimeout?: number
— Timeout in msretry?: { count?: number; delay?: number; onRetry?: Function; shouldRetry?: Function; retryOnSuccess?: boolean }
— Retry options
Response<T = any>
Response object returned from requests.
data: T
— Response datastatus: number
— HTTP status codestatusText: string
— Status textheaders: Record<string, string>
— Response headersconfig: 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 managerinterceptors.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.