@innodata/nuxtjs-alt-http
v1.3.5
Published
An extended module to ohmyfetch
Maintainers
Readme
Information
This serves as an extension to ohmyfetch for nuxt. Please note this is only for nuxt3.
This works similar to nuxt/http and nuxtjs-alt/axios except it utilizes ohmyfetch. All property options will be under http
Other Information
If you want to override the global $fetch function you can do so by setting useConflict to true in your config. This will change:
$httpuseHttpuseLazyHttpglobalThis.$http
to
$fetchuseFetchuseLazyFetchglobalThis.$fetch
Remember this is a mix of ohmyfetch and nuxt/http so to use methods you would use as an example:
// Available methods: 'get', 'head', 'delete', 'post', 'put', 'patch', 'options'
// $http.$get('/api') is the same as $fetch('/api', { method: 'get' })
await $fetch.$get('/api', options)
await $http.$get('/api', options)
// Access Raw Response
// $http.get('/api') is the same as $fetch.raw('/api', { method: 'get' })
await $fetch.get('/api', options)
await $http.get('/api', options)Interceptors
The interceptors should work exactly like how axios has it so to access them you would use:
$http.interceptors.request.use(config)
$http.interceptors.response.use(config)
@nuxtjs-axios based functions have also been added:
$http.onRequest(config)
$http.onResponse(response)
$http.onRequestError(err)
$http.onResponseError(err)
$http.onError(err)Config Options
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
modules: [
'@nuxtjs-alt/http',
],
http: {
}
})Please do tell me if you encounter any bugs.
