mirror of https://github.com/sundowndev/http.git
docs: update usage
parent
c7902eaf69
commit
3949c447f3
|
@ -21,6 +21,8 @@ You can use methods to convert response stream into usable data:
|
||||||
- `arrayBuffer`
|
- `arrayBuffer`
|
||||||
- `blob`
|
- `blob`
|
||||||
|
|
||||||
|
See [ky](https://github.com/sindresorhus/ky#options) docs for all available options.
|
||||||
|
|
||||||
**Example: Get a json file**
|
**Example: Get a json file**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
@ -33,26 +35,10 @@ Alternatively for json only you can use `$` prefixed shortcut:
|
||||||
await $http.$get('https://unpkg.com/nuxt/package.json')
|
await $http.$get('https://unpkg.com/nuxt/package.json')
|
||||||
```
|
```
|
||||||
|
|
||||||
See [ky](https://github.com/sindresorhus/ky#options) docs for all available options.
|
|
||||||
|
|
||||||
### Sending Body
|
|
||||||
|
|
||||||
For sending body alongside with request, you can use either `json` or `body` options.
|
|
||||||
`json` is a shortcut that serializes object using `JSON.stringify` and also sets appreciate `content-type` header.
|
|
||||||
|
|
||||||
**Example: Post with JSON body**
|
**Example: Post with JSON body**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
await $http.post('http://api.con', { json: { foo: 'bar' }})
|
await $http.post('http://api.con', { foo: 'bar' })
|
||||||
```
|
|
||||||
|
|
||||||
**Example: Post with FormData body**
|
|
||||||
|
|
||||||
```js
|
|
||||||
const data = new FormData()
|
|
||||||
data.append('name', 'foo')
|
|
||||||
|
|
||||||
await $http.post('http://api.com/submit', { data })
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using in `asyncData`
|
## Using in `asyncData`
|
||||||
|
|
Loading…
Reference in New Issue