Each http method returns a Promise
$get
(url, options?)
String
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
(url, body?, options?)
String
Object
Error
Examples:
const data = await $http.$post('http://api.com', { foo: 'bar' })
// With some additional options
const data = await $http.$post('http://api.com', { foo: 'bar' }, {
debug: true,
retry: 2,
serverTimeout: 5000
})
$put
(url, body?, options?)
String
Object
Error
Examples:
const data = await $http.$put('http://api.com/{id}', { foo: 'bar' })
// With some additional option
const data = await $http.$put('http://api.com/{id}', { foo: 'bar' }, {
clientTimeout: 5000
})
$delete
(url, options?)
String
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
(url, body?, options?)
String
Object
Error
**Examples: **
const data = await $http.$patch('http://api.com/{id}', { foo: 'bar' })
// With some additional option
const data = await $http.$patch('http://api.com/{id}', { foo: 'bar' }, {
proxyHeaders: true,
proxyHeadersIgnore: ['content-type']
})
$head
(url, options?)
String
Error
get
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
(url, body?, options?)
String
Object
Error
**Examples: **
const response = await $http.post('http://api.com', { foo: 'bar' })
const jsonResponse = await response.json()
// With some additional options
const 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
(url, body?, options?)
String
Object
Error
Examples:
const response = await $http.put('http://api.com/{id}', { foo: 'bar' })
const jsonResponse = await response.json()
// With some additional option
const 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
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
(url, body?, options?)
String
Object
Error
Examples:
const response = await $http.patch('http://api.com/{id}', { foo: 'bar' })
const jsonResponse = await response.json()
// With some additional option
const 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
Example:
await $http.head('https://unpkg.com/nuxt/package.json')
These methods corresponds to the similar named HTTP/1.1 methods.