HTTP Methods


Each http method returns a Promise

$get

  • arguments: (url, options?)
  • resolves: JSON if destr can convert automatically, otherwise fallback to String
  • rejects: Error

Examples:

const package = await $http.$get('https://unpkg.com/nuxt/package.json')
// With prefixUrl option to call `https://example.com/items`const items = await $http.$get('items', { prefixUrl: 'https://example.com' })

$post

  • arguments: (url, body?, options?)
    • url: String
    • body: Object
    • options: options
  • resolves: JSON if destr can convert automatically, otherwise fallback to String
  • rejects: Error

Examples:

const data = await $http.$post('http://api.com', { foo: 'bar' })
// With some additional optionsconst data = await $http.$post('http://api.com', { foo: 'bar' }, {  debug: true,  retry: 2,  serverTimeout: 5000})

$put

  • arguments: (url, body?, options?)
    • url: String
    • body: Object
    • options: options
  • resolves: JSON if destr can convert automatically, otherwise fallback to String
  • rejects: Error

Examples:

const data = await $http.$put('http://api.com/{id}', { foo: 'bar' })
// With some additional optionconst data = await $http.$put('http://api.com/{id}', { foo: 'bar' }, {  clientTimeout: 5000})

$delete

  • arguments: (url, options?)
  • resolves: JSON if destr can convert automatically, otherwise fallback to String
  • rejects: Error

Example:

await $http.$delete('https://api.example.com/item/{id}')
// With some options to call `https://example.com/api/item`const jsonResponse = await $http.$delete('item/{id}', {  baseUrl: 'https://example.com',  prefixUrl: '/api'})

$patch

  • arguments: (url, body?, options?)
    • url: String
    • body: Object
    • options: options
  • resolves: JSON if destr can convert automatically, otherwise fallback to String
  • rejects: Error

Examples:

const data = await $http.$patch('http://api.com/{id}', { foo: 'bar' })
// With some additional optionconst data = await $http.$patch('http://api.com/{id}', { foo: 'bar' }, {  proxyHeaders: true,  proxyHeadersIgnore: ['content-type']})
  • arguments: (url, options?)
  • resolves: -
  • rejects: Error

get

  • arguments: (url, options?)
  • resolves: Response
  • rejects: Error

Examples:

const response = await $http.get('https://unpkg.com/nuxt/package.json')const jsonResponse = await response.json()
// With prefixUrl option to call `https://example.com/items`const response = await $http.get('items', { prefixUrl: 'https://example.com' })const textResponse = await response.text()

See here to convert response stream into usable data.

These methods corresponds to the similar named HTTP/1.1 methods.

post

  • arguments: (url, body?, options?)
    • url: String
    • body: Object
    • options: options
  • resolves: Response
  • rejects: Error

Examples:

const response = await $http.post('http://api.com', { foo: 'bar' })const jsonResponse = await response.json()
// With some additional optionsconst response = await $http.post('http://api.com', { foo: 'bar' }, {  debug: true,  retry: 2,  serverTimeout: 5000})const jsonResponse = await response.json()

See here to convert response stream into usable data.

These methods corresponds to the similar named HTTP/1.1 methods.

put

  • arguments: (url, body?, options?)
    • url: String
    • body: Object
    • options: options
  • resolves: Response
  • rejects: Error

Examples:

const response = await $http.put('http://api.com/{id}', { foo: 'bar' })const jsonResponse = await response.json()
// With some additional optionconst response = await $http.put('http://api.com/{id}', { foo: 'bar' }, {  clientTimeout: 5000})const jsonResponse = await response.json()

See here to convert response stream into usable data.

These methods corresponds to the similar named HTTP/1.1 methods.

delete

  • arguments: (url, options?)
  • resolves: Response
  • rejects: Error

Example:

await $http.delete('https://api.example.com/item/{id}')
// With some options to call `https://example.com/api/item`const response = await $http.delete('item/{id}', {  baseUrl: 'https://example.com',  prefixUrl: '/api'})

See here to convert response stream into usable data.

These methods corresponds to the similar named HTTP/1.1 methods.

patch

  • arguments: (url, body?, options?)
    • url: String
    • body: Object
    • options: options
  • resolves: Response
  • rejects: Error

Examples:

const response = await $http.patch('http://api.com/{id}', { foo: 'bar' })const jsonResponse = await response.json()
// With some additional optionconst response = await $http.patch('http://api.com/{id}', { foo: 'bar' }, {  proxyHeaders: true,  proxyHeadersIgnore: ['content-type']})const jsonResponse = await response.json()

See here to convert response stream into usable data.

These methods corresponds to the similar named HTTP/1.1 methods.

head

  • arguments: (url, options?)
  • resolves: Response
  • rejects: Error

Example:

await $http.head('https://unpkg.com/nuxt/package.json')

These methods corresponds to the similar named HTTP/1.1 methods.