Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update Docus #180

Merged
merged 6 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions docs/content/settings.json

This file was deleted.

19 changes: 19 additions & 0 deletions docs/docus.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
title: 'Http Module',
url: 'https://http.nuxtjs.org',
github: {
repo: 'nuxt/http',
branch: 'main',
releases: true
},
twitter: 'nuxt_js',
theme: {
header: {
title: false,
logo: {
light: '/logo-light.svg',
dark: '/logo-dark.svg'
}
}
}
}
1 change: 1 addition & 0 deletions docs/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { withDocus } from 'docus'

export default withDocus({
rootDir: __dirname,
buildModules: ['vue-plausible'],
plausible: {
domain: 'http.nuxtjs.org'
Expand Down
5 changes: 2 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
"generate": "nuxt generate"
},
"dependencies": {
"docus": "^0.0.8",
"nuxt": "^2.15.0"
"docus": "^0.5.6"
},
"devDependencies": {
"vue-plausible": "^1.1.2"
"vue-plausible": "^1.1.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Setup
description: 'How to setup your module'
category: Getting Started
---

Checkout the [Nuxt documentation](https://nuxtjs.org/api/configuration-modules#the-modules-property) for more information about installing and using modules.
Expand All @@ -10,22 +9,22 @@ Checkout the [Nuxt documentation](https://nuxtjs.org/api/configuration-modules#t

Add `@nuxt/http` dependency to your project:

<code-group>
<code-block label="Yarn" active>
:::::code-group
::::code-block{label="Yarn" active}

```bash
yarn add @nuxt/http
```

</code-block>
<code-block label="NPM">
::::
::::code-block{label="NPM"}

```bash
npm install @nuxt/http
```

</code-block>
</code-group>
::::
:::::

Then add it to the modules section in your `nuxt.config.js`:

Expand All @@ -35,11 +34,9 @@ export default {
}
```

<alert type="success">

:::alert{type="success"}
That's it! You can now use [$http](/usage) in your Nuxt app ✨

</alert>
:::

## Configure

Expand All @@ -59,8 +56,6 @@ export default {

See [http's options](/options).

<alert type="warning">

:::alert{type="warning"}
Note that this module does not currently support IE 11 because of using [ky](https://github.com/sindresorhus/ky) ([open issue](https://github.com/nuxt/http/issues/126))

</alert>
:::
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Usage
description: 'How to use this module'
category: Getting Started
---

## Making Requests
Expand All @@ -11,6 +10,7 @@ See the list of [available HTTP methods](/http-methods).
Calling a HTTP methods returns a `Promise` that resolves to a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object or rejects in case of network errors.

You can use methods to convert response stream into usable data:

- `json`
- `text`
- `formData`
Expand All @@ -29,23 +29,25 @@ console.log(package.name) // log "nuxt"

In most of the case, you want to get the JSON response. You can use `$` prefixed shortcut that smartly parses response using [destr](https://github.com/nuxt-contrib/destr).


Alternatively for other response type, you can use the methods mentioned above:

**Example: GET data as `text`**

```js
const res = await $http.get('https://unpkg.com/nuxt/package.json')
const responseText = await res.text()
```

**Example: GET data as `arrayBuffer`**

```js
const response = await this.$http.get('https://nuxtjs.org/logos/nuxt.svg')
const buffer = await response.arrayBuffer()
console.log('buffer.byteLength = ', buffer.byteLength)
```

**Example: GET data as `readable stream`**

```js
const response = await this.$http.get('https://example.org')
const reader = response.body.getReader()
Expand Down Expand Up @@ -106,11 +108,9 @@ methods: {
}
```

<alert type="info">

:::alert{type="info"}
`this` is not available in Nuxt's `asyncData` method, see [using in `asyncData`](#using-in-asyncdata) for how to use this module in `asyncData`

</alert>
:::

## Using in Store

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
---
title: HTTP Methods
description: 'HTTP Methods'
category: Getting Started
---

<alert type="info">

:::alert{type="info"}
Each http method returns a `Promise`

</alert>
:::

### `$get`

- arguments: `(url, options?)`
- url: `String`
- options: [options](/options)
Expand All @@ -29,6 +27,7 @@ const items = await $http.$get('items', { prefixUrl: 'https://example.com' })
```

### `$post`

- arguments: `(url, body?, options?)`
- url: `String`
- body: `Object`
Expand All @@ -52,6 +51,7 @@ const data = await $http.$post('http://api.com', { foo: 'bar' }, {
```

### `$put`

- arguments: `(url, body?, options?)`
- url: `String`
- body: `Object`
Expand All @@ -73,6 +73,7 @@ const data = await $http.$put('http://api.com/{id}', { foo: 'bar' }, {
```

### `$delete`

- arguments: `(url, options?)`
- url: `String`
- options: [options](/options)
Expand All @@ -94,6 +95,7 @@ const jsonResponse = await $http.$delete('item/{id}', {
```

### `$patch`

- arguments: `(url, body?, options?)`
- url: `String`
- body: `Object`
Expand All @@ -116,13 +118,15 @@ const data = await $http.$patch('http://api.com/{id}', { foo: 'bar' }, {
```

### `$head`

- arguments: `(url, options?)`
- url: `String`
- options: [options](/options)
- resolves: -
- rejects: `Error`

### `get`

- arguments: `(url, options?)`
- url: `String`
- options: [options](/options)
Expand All @@ -147,6 +151,7 @@ See [`here`](/usage#making-requests) 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`
Expand Down Expand Up @@ -176,6 +181,7 @@ See [`here`](/usage#making-requests) 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`
Expand Down Expand Up @@ -203,6 +209,7 @@ See [`here`](/usage#making-requests) to convert response stream into usable data
These methods corresponds to the similar named HTTP/1.1 methods.

### `delete`

- arguments: `(url, options?)`
- url: `String`
- options: [options](/options)
Expand All @@ -228,6 +235,7 @@ See [`here`](/usage#making-requests) 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`
Expand Down Expand Up @@ -256,6 +264,7 @@ See [`here`](/usage#making-requests) to convert response stream into usable data
These methods corresponds to the similar named HTTP/1.1 methods.

### `head`

- arguments: `(url, options?)`
- url: `String`
- options: [options](/options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Advanced
description: 'Advanced concepts'
category: Getting Started
---

## Hooks
Expand Down Expand Up @@ -54,19 +53,15 @@ export default function ({ $http }) {

Globally set a header to all subsequent requests.

<alert type="warning">

:::alert{type="warning"}
This method should probably not be called inside hooks as it is global and will apply to all future requests
:::

</alert>

<alert type="info">

:::alert{type="info"}
Please note that HTTP headers are case-insensitive. Therefore all header names will be converted to lower-case to make sure that if you set the same header twice but with different casing the last one set will be used.

See also [this comment](https://github.com/sindresorhus/ky/issues/105#issuecomment-470169100) in the Ky repository for more information

</alert>
:::

Parameters:

Expand All @@ -91,11 +86,9 @@ this.$http.setHeader('Content-Type', false)

Globally set `Authorization` header to all subsequent requests.

<alert type="info">

:::alert{type="info"}
This is a global method, you only have to call it once after which all future requests will include the token

</alert>
:::

Parameters:

Expand Down
18 changes: 10 additions & 8 deletions docs/content/en/1.index.md → docs/pages/en/1.index.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
---
title: Introduction
description: 'HTTP module for Nuxt.js provides a universal way to make HTTP requests to the API backend.'
category: ''
features:
- The fluent ky API has been extended with enhancements and shortcuts
- Highly customizable options support for `BaseURL`
- Automatically proxy cookies and headers when making requests from server side
- Best practices to avoid token sharing when making server side requests
- Easy proxy support to avoid CORS problems and making deployment easier
---

<img src="/preview.png" class="transition-shadow duration-200 rounded-md shadow light-img hover:shadow-lg" />

<img src="/preview-dark.png" class="transition-shadow duration-200 rounded-md shadow dark-img hover:shadow-lg" />

The HTTP module for [Nuxt](https://nuxtjs.org) provides a universal way to make HTTP requests to any API.
Expand All @@ -23,7 +17,15 @@ Starting from [v2.5.0](https://github.com/nuxt/nuxt.js/releases/tag/v2.5.0), Nux

## Features

<list :items="features"></list>
:::list

- The fluent ky API has been extended with enhancements and shortcuts
- Highly customizable options support for `BaseURL`
- Automatically proxy cookies and headers when making requests from server side
- Best practices to avoid token sharing when making server side requests
- Easy proxy support to avoid CORS problems and making deployment easier

:::

## Links

Expand Down
Loading