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
Copy file name to clipboardExpand all lines: README.md
+3-6Lines changed: 3 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,9 +23,6 @@ npm i -D apiful
23
23
24
24
## Usage
25
25
26
-
> [!TIP]
27
-
> [📖 Read the documentation](https://apiful.land)
28
-
29
26
### Your First API Client
30
27
31
28
Create your first API client by initialising it with a base URL and a sample bearer token for authorization:
@@ -42,7 +39,7 @@ const client = createClient({
42
39
```
43
40
44
41
> [!NOTE]
45
-
> The `createClient` function returns an [`ApiClient`](https://apiful.land/reference/api-client) instance that does not yet have a call signature. You will need to add a base extension to the client in order to make API requests. Read on to learn how to do this.
42
+
> The `createClient` function returns an [`ApiClient`](https://apiful.land/reference/api-client) instance that can't yet make requests. You'll need to add a handler extension to enable HTTP functionality. Read on to learn how to do this.
The `apiRouterBuilder` provides a jQuery-like and Axios-esque API for building and making API requests. It allows you to construct your API calls in a declarative way.
88
+
The `apiRouterBuilder` provides a jQuery-like and Axios-style API for building and making API requests. It allows you to construct your API calls in a declarative way.
If you have specific requirements that are not covered by the included extensions, you can create your own extensions. Follow the [Custom Extensions](https://apiful.land/guide/custom-extensions) guide to learn more.
150
+
If you have specific requirements that aren't covered by the included extensions, you can create your own extensions. Follow the [Custom Extensions](https://apiful.land/guide/custom-extensions) guide to learn more.
Copy file name to clipboardExpand all lines: docs/extensions/api-router.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
> [!NOTE]
4
4
> This is a [handler extension](/guide/custom-extensions#handler-extension) and wraps [ofetch](https://github.com/unjs/ofetch) under the hood.
5
5
6
-
The route builder extension gives you a jQuery-like and Axios-esque API to construct your API calls. This extension is particularly powerful for REST APIs with predictable URL patterns, as it generates zero runtime overhead for property access until you call an HTTP method, at which point it constructs the full URL path and delegates to the underlying HTTP client. This design makes it ideal for APIs with deep nesting (like `/api/v1/organizations/123/projects/456/tasks`) while maintaining excellent TypeScript intellisense throughout the chain:
6
+
The route builder extension gives you a jQuery-like and Axios-style API to construct your API calls. This extension is particularly powerful for REST APIs with predictable URL patterns, as it generates zero runtime overhead for property access until you call an HTTP method, at which point it constructs the full URL path and delegates to the underlying HTTP client. This design makes it ideal for APIs with deep nesting (like `/api/v1/organizations/123/projects/456/tasks`) while maintaining excellent TypeScript intellisense throughout the chain:
Copy file name to clipboardExpand all lines: docs/extensions/ofetch.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
> [!NOTE]
4
4
> This is a [handler extension](/guide/custom-extensions#handler-extension) that wraps [ofetch](https://github.com/unjs/ofetch) under the hood.
5
5
6
-
This built-in extension provides the most straightforward way to make HTTP requests with APIful. It wraps the battle-tested ofetch library with automatic JSON parsing, intelligent error handling, and request/response interception. Since it inherits all default options from the client, it is perfect for developers familiar with fetch or Axios who want enhanced capabilities without complexity.
6
+
This built-in extension provides the most straightforward way to make HTTP requests with APIful. It wraps the battle-tested ofetch library with automatic JSON parsing, intelligent error handling, and request/response interception. Since it inherits all default options from the client, it's perfect for developers familiar with fetch or Axios who want enhanced capabilities without complexity.
7
7
8
8
Import the `ofetchBuilder` extension and add it to your client:
Copy file name to clipboardExpand all lines: docs/extensions/openapi.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ To use this extension, APIful must first generate TypeScript definitions from yo
9
9
10
10
## Prerequisites
11
11
12
-
To keep the package size small, APIful does not include `openapi-typescript` as a dependency. Install the package using your preferred package manager:
12
+
To keep the package size small, APIful doesn't include `openapi-typescript` as a dependency. Install the package using your preferred package manager:
13
13
14
14
::: code-group
15
15
```bash [pnpm]
@@ -24,7 +24,7 @@ To keep the package size small, APIful does not include `openapi-typescript` as
24
24
:::
25
25
26
26
> [!NOTE]
27
-
> `openapi-typescript` is only needed during development for type generation. It will not be included in your production bundle.
27
+
> `openapi-typescript` is only needed during development for type generation. It won't be included in your production bundle.
28
28
29
29
## TypeScript Definitions Generation
30
30
@@ -55,7 +55,7 @@ The type generation process uses `openapi-typescript` to parse your OpenAPI sche
55
55
Done! You can now use the `OpenAPIBuilder` extension to create a type-safe API client. Make sure you pass the **service name** to it as a generic parameter, such as `OpenAPIBuilder<'petStore'>()`. Follow the next chapter for more details.
56
56
57
57
> [!IMPORTANT]
58
-
> Make sure the generated `apiful.d.ts` file is not excluded by your `tsconfig.json` configuration. TypeScript needs to find this file to provide typed definitions for your OpenAPI schema.
58
+
> Make sure the generated `apiful.d.ts` file isn't excluded by your `tsconfig.json` configuration. TypeScript needs to find this file to provide typed definitions for your OpenAPI schema.
59
59
60
60
> [!TIP]
61
61
> Run the generate command whenever your OpenAPI schema changes to keep your types up-to-date. Consider adding it to your build process or a pre-commit hook.
@@ -98,7 +98,7 @@ declare const userResponse: {
98
98
99
99
## OpenAPI Path Parameters
100
100
101
-
OpenAPI can define path parameters on given endpoints. They are typically declared as `/foo/{id}`. Unfortunately, the endpoint type is not defined as `/foo/10`. Thus, using the latter as the path will break type inference.
101
+
OpenAPI can define path parameters on given endpoints. They are typically declared as `/foo/{id}`. Unfortunately, the endpoint type isn't defined as `/foo/10`. Thus, using the latter as the path will break type inference.
102
102
103
103
Instead, use the property `path` to pass an object of the parameters. You can then use the declared path for type inference, and the type checker will ensure you provide all required path parameters. The parameters will be interpolated into the path before the request is made.
> Incorrect parameters will not be reported at runtime. An incomplete path will be sent to the backend _as-is_.
114
+
> Incorrect parameters won't be reported at runtime. An incomplete path will be sent to the backend _as-is_.
115
115
116
116
## Request Headers
117
117
118
-
Add headers to the request using the `headers` field. All headers defined in the OpenAPI schema will be type checked. You can still add additional headers that are not defined in the schema, which will not be type checked.
118
+
Add headers to the request using the `headers` field. All headers defined in the OpenAPI schema will be type checked. You can still add additional headers that aren't defined in the schema, which won't be type checked.
Copy file name to clipboardExpand all lines: docs/guide/cli.md
+2-14Lines changed: 2 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,19 +22,7 @@ The CLI currently provides one primary command:
22
22
23
23
Generates TypeScript definitions from OpenAPI schemas. This is the core command for enabling type-safe API clients.
24
24
25
-
This command requires the `openapi-typescript` package, which APIful does not include by default to keep its package size small. Install the package using your preferred package manager:
26
-
27
-
::: code-group
28
-
```bash [pnpm]
29
-
pnpm add -D openapi-typescript
30
-
```
31
-
```bash [yarn]
32
-
yarn add -D openapi-typescript
33
-
```
34
-
```bash [npm]
35
-
npm install -D openapi-typescript
36
-
```
37
-
:::
25
+
This command requires the `openapi-typescript` package. See the [OpenAPI extension prerequisites](/extensions/openapi#prerequisites) for installation instructions.
38
26
39
27
> [!IMPORTANT]
40
28
> You must have a valid `apiful.config.ts` file with service definitions before running this command.
@@ -62,7 +50,7 @@ This displays the following output:
62
50
<<< @/snippets/generate-help.ansi
63
51
64
52
> [!NOTE]
65
-
> Although it is recommended to create an `apiful.config.ts` file with a [`defineApifulConfig`](/reference/define-apiful-config) default export, you can also write plain JavaScript (`.js`, `.mjs`, `.cjs`) or JSON (`.json`, `.json5`) configuration files.
53
+
> Although it's recommended to create an `apiful.config.ts` file with a [`defineApifulConfig`](/reference/define-apiful-config) default export, you can also write plain JavaScript (`.js`, `.mjs`, `.cjs`) or JSON (`.json`, `.json5`) configuration files.
Copy file name to clipboardExpand all lines: docs/guide/custom-extensions.md
+1-8Lines changed: 1 addition & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,7 @@ APIful's true power lies in its extensibility. You can chain multiple extensions
4
4
5
5
## Extension Types
6
6
7
-
Before creating your first extension, it is essential to understand the two types of extensions available.
8
-
9
-
APIful provides two types of extensions:
10
-
11
-
-**Handler Extension**: Adds the callable signature to a client instance (e.g., `client('/path')`). This provides the core HTTP functionality.
12
-
-**Methods Extension**: Adds methods to the client instance (e.g., `client.login()`, `client.cache.get()`). You can chain multiple method extensions.
13
-
14
-
Both extension types are created using a builder function that receives the client instance and returns the extension function (handler) or object (methods). This builder pattern serves two essential purposes: it provides access to the client instance for reading default options and existing extensions, and it enables TypeScript's type inference to work correctly across the extension chain.
7
+
Before creating your first extension, make sure you understand the [two types of extensions](/guide/extension-types) available: handler extensions (callable signature) and methods extensions (additional methods).
15
8
16
9
> [!IMPORTANT]
17
10
> Use `satisfies HandlerExtensionBuilder` or `satisfies MethodsExtensionBuilder` instead of declaring extension variables directly with these types. The `satisfies` operator is crucial here – it validates that your extension conforms to the expected interface while preserving the exact return type for downstream type inference, ensuring seamless integration with other extensions.
Copy file name to clipboardExpand all lines: docs/guide/getting-started.md
+4-8Lines changed: 4 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## What Is This?
4
4
5
-
APIful provides a unified interface to manage all your API interactions by setting up a client with default fetch options, such as the base API URL and headers. Extensions add a variety of features to the client through a sophisticated proxy-based architecture that maintains full TypeScript type safety while allowing runtime composition. This approach ensures that each extension can enhance or override behavior without breaking the client contract, while keeping bundle sizes minimal through intelligent tree-shaking.
5
+
APIful provides a unified interface to manage all your API interactions by setting up a client with default fetch options, such as the base API URL and headers. Extensions add a variety of features to the client while maintaining full TypeScript type safety. Learn more about [how extensions work](/guide/using-extensions#how-extensions-work).
6
6
7
7
You can use one of the [built-in extensions](/guide/using-extensions#built-in-extensions) to get started right away, or create your own [custom extension](/guide/custom-extensions) to meet your specific needs.
8
8
@@ -23,7 +23,7 @@ Get started by installing `apiful` in your project:
23
23
:::
24
24
25
25
> [!TIP]
26
-
> APIful is designed as a development dependency since it is primarily used for generating types and building API clients during your build process.
26
+
> APIful is designed as a development dependency since it's primarily used for generating types and building API clients during your build process.
27
27
28
28
## Your First API Client
29
29
@@ -41,7 +41,7 @@ const client = createClient({
41
41
```
42
42
43
43
> [!NOTE]
44
-
> The `createClient` function returns an [`ApiClient`](/reference/api-client) instance that cannot yet make requests. You will need to add a handler extension to enable HTTP functionality.
44
+
> The `createClient` function returns an [`ApiClient`](/reference/api-client) instance that can't yet make requests. You'll need to add a handler extension to enable HTTP functionality.
Each extension can implement its own error handling strategy, and errors propagate through the extension chain in a predictable manner. The ofetch extension automatically throws detailed errors with status codes and response bodies, while custom extensions can implement retry logic, circuit breakers, or custom error transformation. This layered approach allows higher-level extensions to catch and transform errors from lower-level ones, giving you complete control over how your application handles API failures.
111
-
112
108
> [!IMPORTANT]
113
109
> When chaining multiple extensions, later extensions override methods from earlier ones. This gives you fine-grained control over the final client behavior.
114
110
115
111
> [!TIP]
116
-
> If you have specific requirements that are not covered by the included extensions, you can create your own extensions. Follow the [Custom Extensions](/guide/custom-extensions) guide to learn more.
112
+
> If you have specific requirements that aren't covered by the included extensions, you can create your own extensions. Follow the [Custom Extensions](/guide/custom-extensions) guide to learn more.
Copy file name to clipboardExpand all lines: docs/reference/create-openapi-client.md
+2-31Lines changed: 2 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,27 +7,13 @@ Creates a type-safe OpenAPI client directly without using the APIful extension s
7
7
Use `createOpenAPIClient` when you:
8
8
9
9
- Want a direct, lightweight OpenAPI client
10
-
- Don not need the extensibility features of the main APIful client system
10
+
- Don't need the extensibility features of the main APIful client system
11
11
- Prefer a simpler API without the `.with()` extension pattern
12
12
- Want to avoid the additional abstraction layer
13
13
14
14
## Prerequisites
15
15
16
-
Same as the [`OpenAPIBuilder`](/extensions/openapi) extension:
17
-
18
-
::: code-group
19
-
```bash [pnpm]
20
-
pnpm add -D openapi-typescript
21
-
```
22
-
```bash [yarn]
23
-
yarn add -D openapi-typescript
24
-
```
25
-
```bash [npm]
26
-
npm install -D openapi-typescript
27
-
```
28
-
:::
29
-
30
-
You also need to generate TypeScript definitions using the [`generate`](/guide/cli) command.
16
+
Same as the [`OpenAPIBuilder`](/extensions/openapi#prerequisites) extension – you need `openapi-typescript` installed and TypeScript definitions generated using the [`generate`](/guide/cli) command.
Copy file name to clipboardExpand all lines: docs/utilities/http-status-codes.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ APIful provides all common HTTP status codes as constants. These are individuall
5
5
All status codes defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), RFC2518 (WebDAV), RFC6585 (Additional HTTP Status Codes), and RFC7538 (Permanent Redirect) are supported.
6
6
7
7
> [!TIP]
8
-
> You may be wondering, why not use the [http-status-codes](https://www.npmjs.com/package/http-status-codes) package directly? Because the enums exported by the package do not work well with frameworks like Hono that use the `@hono/zod-openapi` type system.
8
+
> You may be wondering, why not use the [http-status-codes](https://www.npmjs.com/package/http-status-codes) package directly? Because the enums exported by the package don't work well with frameworks like Hono that use the `@hono/zod-openapi` type system.
0 commit comments