apiful
provides a unified way to manage all your API interactions by setting up a client with default fetch options, such as the API base URL and headers. Adapters extend the client with a variety of features to match your favorite API management flavor.
You can use one of the pre-built adapters to get started quickly, or create your own custom adapter to meet your specific requirements.
# pnpm
pnpm add -D apiful
# npm
npm i -D apiful
import { createClient, ofetch } from 'apiful'
const baseURL = '<your-api-base-url>'
const adapter = ofetch()
const api = createClient({ baseURL }).with(adapter)
// GET request to <baseURL>/users/1
await api('users/1', { method: 'GET' }) | What it does: The |
import { apiRouteBuilder, createClient } from 'apiful'
const baseURL = '<your-api-base-url>'
const adapter = apiRouteBuilder()
const api = createClient({ baseURL }).with(adapter)
// GET request to <baseURL>/users/1
await api.users.get(1)
// POST request to <baseURL>/users with payload
await api.users.post({ name: 'foo' }) | What it does: The |
import { createClient, OpenAPI } from 'apiful'
const baseURL = 'https://petstore3.swagger.io/api/v3'
// Pass pre-generated schema type ID to adapter
const adapter = OpenAPI<'petStore'>()
const api = createClient({ baseURL }).with(adapter)
// Typed parameters and response
const response = await api('/user/{username}', {
method: 'GET',
path: { username: 'user1' },
}) | What it does: If your API has an OpenAPI schema, For example, the response returned by the API call on the left is typed as follows: const response: {
id?: number
username?: string
// …
} Please follow the OpenAPI adapter documentation to learn more about how to generate TypeScript definitions from your OpenAPI schema files. |
As of right now, this library handles API management in the client. In the future, apiful
is intended to extend to the server side as well, providing a unified way to manage API calls in both client and server.
- Clone this repository
- Install latest LTS version of Node.js
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
Made with 💛
Published under MIT License.