UNPKG

@tmlmobilidade/utils

Version:

A collection of utility functions and helpers for the TML Mobilidade Go monorepo, providing common functionality for batching operations, caching, HTTP requests, object manipulation, permissions, and more.

24 lines (23 loc) 1.03 kB
import { HttpResponse } from './response.js'; /** * Fetches data from a URL with configurable HTTP method, body, headers, and options. * @param url - The URL to fetch from * @param method - The HTTP method to use (DELETE, GET, POST, PUT). Defaults to GET. * @param body - Optional request body data * @param headers - Optional request headers * @param options - Optional fetch options (excluding body, headers, method) * @returns Promise resolving to HttpResponse containing data, error and status * @example * ```ts * // GET request * const response = await fetchData<User>('/api/users/123'); * * // POST request with body * const response = await fetchData<User>( * '/api/users', * 'POST', * { name: 'John', email: 'john@example.com' } * ); * ``` */ export declare function fetchData<T>(url: string, method?: 'DELETE' | 'GET' | 'POST' | 'PUT', body?: unknown, headers?: Record<string, string>, options?: Omit<RequestInit, 'body' | 'headers' | 'method'>, retries?: number): Promise<HttpResponse<T>>;