You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
openapi-fetch is a typesafe fetch client that pulls in your OpenAPI schema. Weighs **4 kb** and has virtually zero runtime. Works with React, Vue, Svelte, or vanilla JS.
7
+
openapi-fetch is a typesafe fetch client that pulls in your OpenAPI schema. Weighs **5 kb** and has virtually zero runtime. Works with React, Vue, Svelte, or vanilla JS.
The syntax is inspired by popular libraries like react-query or Apollo client, but without all the bells and whistles and in a 4 kb package.
17
+
The syntax is inspired by popular libraries like react-query or Apollo client, but without all the bells and whistles and in a 5 kb package.
18
18
19
19
```ts
20
20
importcreateClientfrom"openapi-fetch";
@@ -49,7 +49,7 @@ Notice there are no generics, and no manual typing. Your endpoint’s request an
49
49
- ✅ No manual typing of your API
50
50
- ✅ Eliminates `any` types that hide bugs
51
51
- ✅ Also eliminates `as` type overrides that can also hide bugs
52
-
- ✅ All of this in a **4 kb** client package 🎉
52
+
- ✅ All of this in a **5 kb** client package 🎉
53
53
54
54
## Setup
55
55
@@ -94,7 +94,7 @@ And run `npm run test:ts` in your CI to catch type errors.
94
94
Use `tsc --noEmit` to check for type errors rather than relying on your linter or your build command. Nothing will typecheck as accurately as the TypeScript compiler itself.
95
95
:::
96
96
97
-
## Basic Usage
97
+
## Basic usage
98
98
99
99
The best part about using openapi-fetch over oldschool codegen is no documentation needed. openapi-fetch encourages using your existing OpenAPI documentation rather than trying to find what function to import, or what parameters that function wants:
Copy file name to clipboardExpand all lines: docs/openapi-fetch/middleware-auth.md
+7-9
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ title: Middleware & Auth
4
4
5
5
# Middleware & Auth
6
6
7
-
## Middleware
7
+
Middleware allows you to modify either the request, response, or both for all fetches. One of the most common usecases is authentication, but can also be used for logging/telemetry, throwing errors, or handling specific edge cases.
8
8
9
-
Middleware allows you to modify either the request, response, or both for all fetches.
9
+
## Middleware
10
10
11
11
Each middleware can provide `onRequest()` and `onResponse()` callbacks, which can observe and/or mutate requests and responses.
The order in which middleware are registered matters. For requests, `onRequest()` will be called in the order registered. For responses, `onResponse()` will be called in **reverse** order. That way the first middleware gets the first “dibs” on requests, and the final control over responses.
39
-
40
-
:::
36
+
> [!TIP]
37
+
>
38
+
> The order in which middleware are registered matters. For requests, `onRequest()` will be called in the order registered. For responses, `onResponse()` will be called in **reverse** order. That way the first middleware gets the first “dibs” on requests, and the final control over the end response.
This library is unopinionated and can work with any [Authorization](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization) setup. But here are a few suggestions that may make working with auth easier.
110
108
111
-
### Basic Auth
109
+
### Basic auth
112
110
113
111
This basic example uses middleware to retrieve the most up-to-date token at every request. In our example, the access token is kept in JavaScript module state, which is safe to do for client applications but should be avoided for server applications.
0 commit comments