# unjs/ofetch

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/unjs-ofetch).**

5,150 stars · 152 forks · TypeScript · mit

## Links

- GitHub: https://github.com/unjs/ofetch
- awesome-repositories: https://awesome-repositories.com/repository/unjs-ofetch.md

## Description

ofetch is an HTTP client built on the native fetch API that adds automatic JSON serialization, request/response interceptors, configurable retry, and timeout handling. It provides descriptive error objects for non-OK responses and automatically parses response bodies based on their content type.

The client supports creating pre-configured instances with preset base URLs, headers, and default options, enabling consistent configuration across a project. It offers full TypeScript type inference for response data and request payloads, and allows extending request options with custom properties while preserving type safety. Additional capabilities include hooking into the request lifecycle via async interceptors, routing requests through proxy servers using standard environment variables, and consuming Server-Sent Events streams in real time.

The library also provides flexible error handling with parsed response bodies, the ability to access raw Response objects, and support for request body serialization including binary data. ofetch is available as a TypeScript package and can be installed via common JavaScript package managers.

## Tags

### Web Development

- [Fetch API Wrappers](https://awesome-repositories.com/f/web-development/restful-api-clients/node-js-clients/fetch-api-wrappers.md) — Wraps the native fetch API with additional features like interceptors, retry, and timeout.
- [API Request Configurations](https://awesome-repositories.com/f/web-development/api-request-configurations.md) — Configures base URL, query parameters, and custom headers that apply to each request. ([source](https://github.com/unjs/ofetch/blob/main/README.md))
- [Descriptive HTTP Error Responses](https://awesome-repositories.com/f/web-development/backend-development/request-response-handling/descriptive-http-error-responses.md) — Throws descriptive errors that include the parsed response body for non-OK HTTP responses. ([source](https://github.com/unjs/ofetch/tree/v1))
- [HTTP Error Handling](https://awesome-repositories.com/f/web-development/http-error-handling.md) — Throws descriptive errors with parsed response body for non-OK statuses. ([source](https://github.com/unjs/ofetch/blob/main/README.md))
- [Descriptive HTTP Error Responses](https://awesome-repositories.com/f/web-development/http-error-handling/descriptive-http-error-responses.md) — Provides descriptive error objects containing the parsed response body for failed HTTP requests.
- [HTTP Request Interceptors](https://awesome-repositories.com/f/web-development/http-request-interceptors.md) — Provides async interceptors that hook into the request and response lifecycle for modification and logging.
- [Content-Type Based Deserializers](https://awesome-repositories.com/f/web-development/request-body-deserializers/request-and-response-transformers/content-type-based-deserializers.md) — Automatically parses response bodies as JSON, blob, or text based on the Content-Type header.
- [Request Body Attachers](https://awesome-repositories.com/f/web-development/request-body-handling/request-body-alterations/request-body-attachers.md) — Automatically stringifies JSON request bodies and sets Content-Type headers, with binary support. ([source](https://github.com/unjs/ofetch/blob/main/README.md))
- [Request Lifecycle Hooks](https://awesome-repositories.com/f/web-development/request-lifecycle-hooks.md) — Provides async hooks for logging, authentication, and dynamic modification during request lifecycle. ([source](https://github.com/unjs/ofetch/blob/main/README.md))
- [Request-Response Interceptors](https://awesome-repositories.com/f/web-development/request-response-interceptors.md) — Enables global interceptors to modify or log outgoing requests and incoming responses. ([source](https://github.com/unjs/ofetch/blob/main/CHANGELOG.md))
- [Type-Safe API Clients](https://awesome-repositories.com/f/web-development/type-safe-api-clients.md) — Provides full TypeScript type inference for response data and request payloads, ensuring type-safe client-server communication.

### Data & Databases

- [JSON Request Serializers](https://awesome-repositories.com/f/data-databases/json-request-serializers.md) — Automatically stringifies object request bodies as JSON and sets the appropriate Content-Type header. ([source](https://github.com/unjs/ofetch#readme))

### DevOps & Infrastructure

- [Automatic Body Deserializers](https://awesome-repositories.com/f/devops-infrastructure/response-parsing-utilities/automatic-body-deserializers.md) — Automatically converts response data into JSON or Blob based on Content-Type header. ([source](https://github.com/unjs/ofetch#readme))
- [Response Body Parsing](https://awesome-repositories.com/f/devops-infrastructure/response-parsing-utilities/response-body-parsing.md) — Automatically parses HTTP response bodies as JSON, text, or binary based on content type. ([source](https://github.com/unjs/ofetch/tree/v1))
- [Request Retries](https://awesome-repositories.com/f/devops-infrastructure/api-service-management/api-resilience/request-retries.md) — Automatically retries failed HTTP requests with configurable status codes, count, and delay. ([source](https://github.com/unjs/ofetch/blob/main/CHANGELOG.md))
- [Server Error Retries](https://awesome-repositories.com/f/devops-infrastructure/api-service-management/api-resilience/request-retries/server-error-retries.md) — Retries requests automatically on server error status codes with configurable delay and count. ([source](https://github.com/unjs/ofetch#readme))

### Networking & Communication

- [HTTP Request Abstractions](https://awesome-repositories.com/f/networking-communication/http-request-abstractions.md) — Provides a feature-rich fetch wrapper that adds retries, timeouts, and automatic error handling.
- [HTTP Request Customization](https://awesome-repositories.com/f/networking-communication/http-request-customization.md) — Merges custom base URL, query parameters, headers, and timeout into every request. ([source](https://github.com/unjs/ofetch#readme))
- [Fetch-Based HTTP Clients](https://awesome-repositories.com/f/networking-communication/isomorphic-http-clients/fetch-based-http-clients.md) — Ships a full-featured HTTP client built on the native fetch API with automatic JSON parsing, interceptors, retry, and timeout handling.
- [Client Instance Defaults](https://awesome-repositories.com/f/networking-communication/remote-access-control/client-configuration-settings/client-instance-defaults.md) — Creates reusable HTTP client instances with preset base URL, headers, and default options.
- [Retry Policies](https://awesome-repositories.com/f/networking-communication/retry-policies.md) — Provides configurable retry of failed requests with custom status codes and delay between attempts.
- [Type-Safe Option Extensions](https://awesome-repositories.com/f/networking-communication/http-request-customization/request-object-extensions/type-safe-option-extensions.md) — Adds custom properties to request configuration objects while preserving full type safety. ([source](https://github.com/unjs/ofetch/blob/main/README.md))
- [Request Abort Signals](https://awesome-repositories.com/f/networking-communication/request-abort-signals.md) — Supports request timeout and custom cancellation signals to abort ongoing requests. ([source](https://github.com/unjs/ofetch/blob/main/CHANGELOG.md))

### Testing & Quality Assurance

- [API Request Configurations](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-utilities-assertions/network-api-mocking/api-request-configurations.md) — Configures base URLs, default headers, and query parameters that apply to every request.
- [Pre-Configured HTTP Clients](https://awesome-repositories.com/f/testing-quality-assurance/http-request-clients/pre-configured-http-clients.md) — Offers a factory function to create reusable HTTP clients with preset base URLs, headers, and default options.

### Software Engineering & Architecture

- [Response Type Inference](https://awesome-repositories.com/f/software-engineering-architecture/response-type-inference.md) — Infers response data types automatically so editors provide autocomplete for fields. ([source](https://github.com/unjs/ofetch/blob/main/README.md))

### System Administration & Monitoring

- [Request Timeouts](https://awesome-repositories.com/f/system-administration-monitoring/request-timeouts.md) — Aborts requests that exceed a specified time limit to prevent hanging connections. ([source](https://github.com/unjs/ofetch/blob/main/README.md))
