ofetch Adapter
import { createClient, ofetch } from 'apiverse'
const baseURL = '<your-api-base-url>'
const adapter = ofetch()
const api = createClient({ baseURL }).with(adapter)
await api('users/1', { method: 'GET' })
|
What it does:
The ofetch adapter wraps ofetch to handle API calls.
|
apiRouteBuilder Adapter
import { apiRouteBuilder, createClient } from 'apiverse'
const baseURL = '<your-api-base-url>'
const adapter = apiRouteBuilder()
const api = createClient({ baseURL }).with(adapter)
await api.users.get(1)
await api.users.post({ name: 'foo' })
|
What it does:
The apiRouteBuilder adapter provides a jQuery-like and Axios-esque API for building and making API calls. It allows you to construct your API calls in a declarative way.
|
OpenAPI Adapter
import { OpenAPI, createClient } from 'apiverse'
const baseURL = 'https://petstore3.swagger.io/api/v3'
const adapter = OpenAPI<'petStore'>()
const api = createClient({ baseURL }).with(adapter)
const response = await api('/user/{username}', {
method: 'GET',
path: { username: 'user1' },
})
|
What it does:
If your API has an OpenAPI schema, apiverse can use it to generate types for you, which the OpenAPI adapter then consumes to provide type-safe API calls.
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.
|