@innodata/nuxtjs-alt-http
TypeScript icon, indicating that this package has built-in type declarations

1.3.5 • Public • Published

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:

  • $http
  • useHttp
  • useLazyHttp
  • globalThis.$http

to

  • $fetch
  • useFetch
  • useLazyFetch
  • globalThis.$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.

Package Sidebar

Install

npm i @innodata/nuxtjs-alt-http

Weekly Downloads

1

Version

1.3.5

License

MIT

Unpacked Size

15.5 kB

Total Files

11

Last publish

Collaborators

  • artemprodigy