HttpClient

class HttpClient<TRoutes> - TRoutes is typically typeof server via import type.

Constructor

new HttpClient<TRoutes>(options: HttpClientOptions)

  • baseUrl: string
  • headers?: Record<string, string>
  • fetch?: typeof fetch

Methods

get / post / put / patch / delete(url, input?) - input accepts params, query, body, headers as required by the route. Resolves to the union of handler response shapes.

HttpClientError

Thrown on non-2xx: status: number, body: unknown, url: string.

Empty responses (204) yield null. Non-JSON bodies return as text. Guide: Typed client.