A fetch client you compose – typed from your OpenAPI schema, no generated client code
See the codeAPIful 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 to match your favorite flavor of API management.
You can use one of the built-in extensions to get started right away, or create your own custom extension to meet your specific needs.
[!TIP] 📖 Read the documentation
[!NOTE] Upgrading from v4? See the migration guide.
# pnpm
pnpm add apiful
# npm
npm i apiful
Create your first API client by initializing it with a base URL and a sample bearer token for authorization:
import { createClient } from 'apiful'
const client = createClient({
baseURL: 'https://api.example.com',
headers: {
Authorization: `Bearer ${process.env.API_KEY}`,
},
})
[!NOTE] The
createClientfunction returns anApiClientinstance 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.
| What it does: The |
| What it does: The |
| What it does: If your API has an OpenAPI schema, APIful can use it to generate types for you, which the For example, the response returned by the API call on the left is typed as follows:
Follow the OpenAPI extension documentation to learn more about how to generate TypeScript definitions from your OpenAPI schema files. |
Each client can have more than one extension. This means that you can chain with methods to add multiple extensions to your client.
For example, you can add a custom extension to log the default fetch options:
import type { MethodsExtensionBuilder } from 'apiful'
const logExtension = (client => ({
logDefaults() {
console.log('Default fetch options:', client.defaultOptions)
}
})) satisfies MethodsExtensionBuilder
const extendedClient = client
.with(logExtension)
extendedClient.logDefaults() // { baseURL: 'https://api.example.com', headers: { Authorization: 'Bearer <your-bearer-token>' } }
If you have specific requirements that aren't covered by the included extensions, you can create your own extensions. Follow the Custom Extensions guide to learn more.
corepack enablepnpm installpnpm testMade with 💛
Published under MIT License.
416 commits
7 commits
TypeScript
100.0%
A fetch client you compose – typed from your OpenAPI schema, no generated client code
See the codeAPIful 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 to match your favorite flavor of API management.
You can use one of the built-in extensions to get started right away, or create your own custom extension to meet your specific needs.
[!TIP] 📖 Read the documentation
[!NOTE] Upgrading from v4? See the migration guide.
# pnpm
pnpm add apiful
# npm
npm i apiful
Create your first API client by initializing it with a base URL and a sample bearer token for authorization:
import { createClient } from 'apiful'
const client = createClient({
baseURL: 'https://api.example.com',
headers: {
Authorization: `Bearer ${process.env.API_KEY}`,
},
})
[!NOTE] The
createClientfunction returns anApiClientinstance 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.
| What it does: The |
| What it does: The |
| What it does: If your API has an OpenAPI schema, APIful can use it to generate types for you, which the For example, the response returned by the API call on the left is typed as follows:
Follow the OpenAPI extension documentation to learn more about how to generate TypeScript definitions from your OpenAPI schema files. |
Each client can have more than one extension. This means that you can chain with methods to add multiple extensions to your client.
For example, you can add a custom extension to log the default fetch options:
import type { MethodsExtensionBuilder } from 'apiful'
const logExtension = (client => ({
logDefaults() {
console.log('Default fetch options:', client.defaultOptions)
}
})) satisfies MethodsExtensionBuilder
const extendedClient = client
.with(logExtension)
extendedClient.logDefaults() // { baseURL: 'https://api.example.com', headers: { Authorization: 'Bearer <your-bearer-token>' } }
If you have specific requirements that aren't covered by the included extensions, you can create your own extensions. Follow the Custom Extensions guide to learn more.
corepack enablepnpm installpnpm testMade with 💛
Published under MIT License.
416 commits
7 commits
TypeScript
100.0%