Skip to content

Latest commit

 

History

History
73 lines (47 loc) · 1.33 KB

3.helpers.md

File metadata and controls

73 lines (47 loc) · 1.33 KB

Helpers

Helpers available on $http instance.


::alert{type="info"} 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 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')
}

getBaseURL

Get the value of the base URL

// Get baseURL value
this.$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 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.