Client
Officialv5.5.8@kubb/plugin-client
Call operations
Each generated function takes one grouped options object and returns your client's promise.
import { addPet, getPetById } from './gen/clients'
const created = await addPet({ body: { name: 'Odie', photoUrls: [] } })
console.log(created.data, created.response.status)
const pet = await getPetById({ path: { petId: 1n } })The keys are path, query, headers, and body. Kubb types each from the spec, so a wrong key or value fails at compile time.
Errors
throwOnError defaults to true (see throwOnErrorDefault). What that means is up to your client. With the example client, a non-2xx status throws, and throwOnError: false returns the error as a value:
const result = await getPetById({ path: { petId: 1n }, throwOnError: false })
if (result.error === undefined) {
console.log('pet', result.data.name)
}
if (result.error !== undefined) {
console.log('failed', result.response.status)
}Use a different client for one call
Pass client to send one call through another function:
await getPetById({ path: { petId: 2n }, client: tenantClient })Authenticate
Auth lives in your client. The plugin does not send credentials itself. It tells your client which schemes each operation needs, and your client decides what to do.
Validate requests and responses
@kubb/plugin-client does not validate on its own. With validator set, it passes the schemas to your client, which runs them.