Helpers

Helpers available on $http instance.


Helpers available on $http instance.

setBaseURL

  • arguments: (baseURL)

Globally set a base URL to all subsequent requests

// Set baseURL (both client and server)this.$http.setBaseURL('http://api.example.com')// Change URL only for clientif (process.client) {  this.$http.setBaseURL('http://api.example.com')}// Change URL only for serverif (process.server) {  this.$http.setBaseURL('http://api.example.com')}

getBaseURL

Get the value of the base URL

// Get baseURL valuethis.$http.getBaseURL()

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 requeststhis.$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.