HTTP Methods
Each http method returns a
Promise$get
- arguments:
(url, options?)- url:
String - options: options
- url:
- 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
- url:
- 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
- url:
- 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?)- url:
String - options: options
- url:
- 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
- url:
- 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']})$head
- arguments:
(url, options?)- url:
String - options: options
- url:
- resolves: -
- rejects:
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
- arguments:
(url, body?, options?)- url:
String - body:
Object - options: options
- url:
- 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
- url:
- 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
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
- url:
- 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
Example:
await $http.head('https://unpkg.com/nuxt/package.json')These methods corresponds to the similar named HTTP/1.1 methods.