Setup

How to setup your module.


Checkout the Nuxt documentation for more information about installing and using modules.

Install

Add @nuxt/http dependency to your project:

Yarn
yarn add @nuxt/http
NPM
npm install @nuxt/http

Then add it to the modules section in your nuxt.config.js:

nuxt.config.js
export default {  modules: ['@nuxt/http']}
That's it! You can now use $http in your Nuxt app ✨

Configure

Add a http object to your nuxt.config.js to configure global options which will be applied to all requests

nuxt.config.js
export default {  modules: [    '@nuxt/http',  ],  http: {    // proxyHeaders: false  }}

See http's options.

Note that this module does not currently support IE 11 because of using ky (open issue)

TypeScript

Add the types to your "types" array in tsconfig.json after the @nuxt/types (Nuxt 2.9.0+) or @nuxt/vue-app entry

tsconfig.json
{  "compilerOptions": {    "types": [      "@nuxt/types",      "@nuxt/http"    ]  }}

Why?

Because of the way Nuxt works the $http property on the context has to be merged into the Nuxt Context interface via declaration merging. Adding @nuxt/http to your types will import the types from the package and make typescript aware of the additions to the Context interface.