use[Client]
Composables are generated for each OpenAPI client specified in the openFetch
section of Nuxt config and provide a convenient wrapper around useFetch
.
Usage
It has the same API as Nuxt's useFetch
composable with additional path
option, which is used to replace params in the pathname.
For other options, see additional parameters.
<script setup lang="ts">
const { data } = await usePets('/pet/{petId}', {
path: {
petId: 12
}
})
</script>
<template>
<h1>{{ data?.name }}</h1>
</template>
Additional parameters
In addition to the useFetch
options, the composable accepts the following additional parameters:
path
- Type:
Record<string, string | number>
The exact type of the path
is generated from the OpenAPI schema for type safety and autocompletion.
This option lets you replace the path parameters in the endpoint URL with the actual values.
accept
- Type:
MediaType | MediaType[]
The exact type of the accept
option is generated from the available response types in the OpenAPI schema.
This option allows you to set the Accept
header for the request and typeset the result type accordingly.
accept
option will always override the Accept
header sent by the underlying client, even if overridden in the useFetch
options.For more examples, see Response types.