Helpers

Helpers available on $http instance.

setBaseURL

  • arguments: (baseURL)

Globally set a header to all subsequent requests

// Set baseURL (both client and server)
this.$http.setBaseURL('http://api.example.com')

// Change URL only for client
if (process.client) {
  this.$http.setBaseURL('http://api.example.com')
}

// Change URL only for server
if (process.server) {
  this.$http.setBaseURL('http://api.example.com')
}

setHeader

  • arguments: (name, value)

Globally set a header to all subsequent requests

**Example: **

// Add header `Content-Type: application/json`
this.$http.setHeader('Content-Type', 'application/json')

See here for usage.

setToken

  • arguments: (token, type)

Globally set a Authorization header for all subsequent requests.

// Adds header: `Authorization: Bearer 123` to all requests
this.$http.setToken('123', 'Bearer')

See here for usage.

create

  • arguments: (kyOptions)

Create a new KY instance based on defaults, see create new instance based on defaults for usage.