nuxt / http

Universal HTTP Module for Nuxt.js
https://http.nuxtjs.org
MIT License
229 stars 51 forks source link

allow creating new instances #3

Closed pi0 closed 4 years ago

pi0 commented 5 years ago

Advanced use case. Inside a plugin create a new instance for multi baseURL or custom headers support.

plugins/http.js

export default function ({ $http }, inject) {
  inject(blog, $http.extend({
    baseURL: 'http://blog.mywebsite.com/api'
  }))
}
warheartvik commented 5 years ago

Hello,

This is my current api set up using axios.

image

I have a centralized method, which spects the HTTP method, URL, Params and the data:

async Execute (method: any, resource: any, params: any, data: any)

So all my api calls, just send de needed data, like this:

Ejecutar (data: any, direccion: any) { return this.Execute('post', direccion,'', data); }

Is there a way to acomplish this by now using @nuxt/http?

pi0 commented 4 years ago

Feature implemented by in v0.5.0

pi0 commented 4 years ago

@warheartvik You have to create a Nuxt plugin. Please see docs: https://http.nuxtjs.org/guide/advanced.html#create-new-instance-based-on-defaults