OP

Openapi Fetch

openapi-fetch

Fast, type-safe fetch client for your OpenAPI schema. Only 6 kb (min). Works with React, Vue, Svelte, or vanilla JS.

Data Fetching
openapi
swagger
rest
api
oapi_3
oapi_3_1
typescript
fetch
react
vue
Stars
8.4k
Weekly
0
Open issues
295
Bundle
~60 kB

Installation

npm install openapi-fetch

Code example

import { useOpenapiFetch } from "openapi-fetch";

export function Example() {
  const { data, isLoading, error } = useOpenapiFetch({
    queryKey: ["example"],
    queryFn: () => fetch("/api/example").then((r) => r.json()),
  });

  if (isLoading) return <p>Loading…</p>;
  if (error) return <p>Could not load data.</p>;
  return <pre>{JSON.stringify(data, null, 2)}</pre>;
}

Pros & cons

Pros

  • Actively maintained by Drew Powers
  • 0 weekly downloads. Battle tested
  • First-class TypeScript definitions
  • MIT licensed

Considerations

  • Adds roughly ~60 kB to your bundle
  • Needs client-only rendering in SSR frameworks
  • Not supported in React Native
  • 295 open issues on GitHub

FAQs

Alternatives & similar libraries