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

docs: update public API relative usage #6318

Merged
merged 10 commits into from
Feb 22, 2022
36 changes: 24 additions & 12 deletions docs/en/latest/plugins/batch-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,35 @@ Response is `Array` of [HttpResponse](#httpresponse).

## How to specify custom uri

We can change the default uri in the `plugin_attr` section of `conf/config.yaml`.
We have the [public-api](public-api.md) plugin, customizing the uri becomes even easier. We just need to set the `uri` you want when creating the route and change the configuration of the `public-api` plugin.

| Name | Type | Requirement | Default | Description |
| ---------- | ------ |-------------| ---------------------------- | --------------------------------- |
| uri | string | optional | "/apisix/batch-requests" | uri to use with batch-requests plugin |

Here is an example:

```yaml
plugin_attr:
batch-requests:
uri: "/api-gw/batch"
```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/br -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/batch-requests",
"plugins": {
"public-api": {
"uri": "/apisix/batch-requests"
}
}
}'
```

## Test Plugin

You can pass your request detail to batch API( `/apisix/batch-requests` ), `apisix` can automatically complete requests via [http pipeline](https://en.wikipedia.org/wiki/HTTP_pipelining). Such as:
First you need to setup the route for the API that batch request, which will use the [public-api](public-api.md) plugin.

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/br -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/batch-requests",
"plugins": {
"public-api": {}
}
}'
```

Then, you can pass your request detail to batch API( `/apisix/batch-requests` ), APISIX can automatically complete requests via [http pipeline](https://en.wikipedia.org/wiki/HTTP_pipelining). Such as:
bzp2010 marked this conversation as resolved.
Show resolved Hide resolved

```shell
curl --location --request POST 'http://127.0.0.1:9080/apisix/batch-requests' \
Expand Down
14 changes: 14 additions & 0 deletions docs/en/latest/plugins/jwt-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ then add jwt-auth plugin in the Consumer page:

#### Get the Token in `jwt-auth` Plugin:

First you need to setup the route for the API that sign the token, which will use the [public-api](public-api.md) plugin.
bzp2010 marked this conversation as resolved.
Show resolved Hide resolved

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/jas -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/plugin/jwt/sign",
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
"plugins": {
"public-api": {}
}
}'
```

Let's get a token.

* without extension payload:

```shell
Expand Down
18 changes: 17 additions & 1 deletion docs/en/latest/plugins/node-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ plugins: # plugin list
......
```

After starting `APISIX`, you can get status information through the API `/apisix/status`.
2. Setup the route for the status API, which will use the [public-api](public-api.md) plugin.

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/ns -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/status",
"plugins": {
"public-api": {}
}
}'
```

## Test Plugin

Expand Down Expand Up @@ -121,3 +131,9 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f
"plugins": {}
}'
```

3. You can also remove the route on `/apisix/status`, no one can access the API.

```sh
$ curl http://127.0.0.1:9080/apisix/admin/routes/ns -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X DELETE
```
36 changes: 25 additions & 11 deletions docs/en/latest/plugins/prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ Then add prometheus plugin:

We fetch the metric data from the specified url `/apisix/prometheus/metrics`.

First you need to setup the route for the metrics API, which will use the [public-api](public-api.md) plugin.
bzp2010 marked this conversation as resolved.
Show resolved Hide resolved

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/p -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/prometheus/metrics",
"plugins": {
"public-api": {}
}
}'
```

Then, we can get the metrics.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to do it for prometheus, which uses a different port.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now that we have introduced public-api plugin, can we reduce the existence of APIs with special configuration items on these plugins and let users give priority to using public-api plugin to realize similar functions, such as prometheus plugin and batch-requests plugins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default port of Prometheus metrics is 9091, not the 9080.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not recommended to configure the port to 9080, which abuses the 9080 port and should be only used in the CI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove the example of public-api in prometheus. Better not encourage the abuse.

Copy link
Contributor Author

@bzp2010 bzp2010 Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spacewander changes rolled back


```
curl -i http://127.0.0.1:9091/apisix/prometheus/metrics
```
Expand All @@ -119,18 +133,18 @@ And we can check the status at prometheus console:

## How to specify export uri

We can change the default export uri in the `plugin_attr` section of `conf/config.yaml`.

| Name | Type | Default | Description |
| ---------- | ------ | ---------------------------- | --------------------------------- |
| export_uri | string | "/apisix/prometheus/metrics" | uri to get the prometheus metrics |
We have the [public-api](public-api.md) plugin, customizing the export uri becomes even easier. We just need to set the `uri` you want when creating the route and change the configuration of the `public-api` plugin.

Here is an example:

```yaml
plugin_attr:
prometheus:
export_uri: /apisix/metrics
```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/p -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/metrics",
"plugins": {
"public-api": {
"uri": "/apisix/prometheus/metrics"
}
}
}'
```

### Grafana dashboard
Expand Down
16 changes: 16 additions & 0 deletions docs/en/latest/plugins/wolf-rbac.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f1

## Test Plugin

#### Setup routes for public API

Use the `public-api` plugin to expose the public API.

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/wal -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/plugin/wolf-rbac/login",
"plugins": {
"public-api": {}
}
}'
```

You also need to setup the `change_pwd` and `user_info` routes together.

#### Login and get `wolf-rbac` token:

The following `appid`, `username`, and `password` must be real ones in the wolf system.
Expand Down
36 changes: 24 additions & 12 deletions docs/zh/latest/plugins/batch-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,35 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/batch-requests -H 'X-API

## 如何修改自定义 uri

我们可以在 `conf/config.yaml` 的 `plugin_attr` 配置项中修改默认的 `uri`
我们可以使用 [public-api](../../../en/latest/plugins/public-api.md) 插件轻易的设置自定义 uri。只需要在创建路由时设置需要的 uri 并改变 `public-api` 插件的配置即可。

| 名称 | 类型 | 必选项 | 默认值 | 描述 |
| --------- | ------ | ------ | ---------------------------- | -------------- |
| uri | string | 可选 |"/apisix/batch-requests" | `batch-requests` 插件的自定义 uri |

配置示例:

```yaml
plugin_attr:
batch-requests:
uri: "/api-gw/batch"
```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/br -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/batch-requests",
"plugins": {
"public-api": {
"uri": "/apisix/batch-requests"
}
}
}'
```

## 测试插件

你可以将要访问的请求信息传到网关的批量请求接口( `/apisix/batch-requests` ),网关会以 [http pipeline](https://en.wikipedia.org/wiki/HTTP_pipelining) 的方式自动帮你完成请求。
首先,你需要为 batch request 的 API 设置一个路由,它将使用 [public-api](public-api.md) 插件。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[public-api](public-api.md) only has English version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broken link fixed


```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/br -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/batch-requests",
"plugins": {
"public-api": {}
}
}'
```

之后,你就可以将要访问的请求信息传到网关的批量请求接口( `/apisix/batch-requests` )了,网关会以 [http pipeline](https://en.wikipedia.org/wiki/HTTP_pipelining) 的方式自动帮你完成请求。

```shell
curl --location --request POST 'http://127.0.0.1:9080/apisix/batch-requests' \
Expand Down
14 changes: 14 additions & 0 deletions docs/zh/latest/plugins/jwt-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13

#### 首先进行登录获取 `jwt-auth` token:

首先,你需要为签发 token 的 API 设置一个路由,它将使用 [public-api](public-api.md) 插件。

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/jas -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/plugin/jwt/sign",
"plugins": {
"public-api": {}
}
}'
```

之后,我们就可以调用它获取 token 了。

* 没有额外的 payload:

```shell
Expand Down
12 changes: 11 additions & 1 deletion docs/zh/latest/plugins/node-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ plugins: # plugin list
......
```

启动 `APISIX` 之后,即可访问该插件提供的接口,获得基本的状态信息。
2. 为状态 API 配置路由,它将使用 [public-api](public-api.md) 插件。

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/ns -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/status",
"plugins": {
"public-api": {}
}
}'
```

## 测试插件

Expand Down
36 changes: 24 additions & 12 deletions docs/zh/latest/plugins/prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,19 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13

## 如何提取指标数据

我们可以从指定的 url 中提取指标数据 `/apisix/prometheus/metrics`:
我们可以从指定的 url 中提取指标数据 `/apisix/prometheus/metrics`。为此,您需要先为它配置一个路由,它将使用 [public-api](../../../en/latest/plugins/public-api.md) 插件。

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/p -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/prometheus/metrics",
"plugins": {
"public-api": {}
}
}'
```

然后,我们就可以获取指标数据了。

```
curl -i http://127.0.0.1:9091/apisix/prometheus/metrics
Expand All @@ -118,18 +130,18 @@ scrape_configs:

## 如何修改暴露指标的 uri

我们可以在 `conf/config.yaml` 的 `plugin_attr` 修改默认的 uri

| 名称 | 类型 | 默认值 | 描述 |
| ---------- | ------ | ---------------------------- | -------------- |
| export_uri | string | "/apisix/prometheus/metrics" | 暴露指标的 uri |

配置示例:
我们可以使用 [public-api](../../../en/latest/plugins/public-api.md) 插件轻易的改变暴露指标的 uri。只需要在创建路由时设置需要的 uri 并改变 `public-api` 插件的配置即可。

```yaml
plugin_attr:
prometheus:
export_uri: /apisix/metrics
```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/p -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/metrics",
"plugins": {
"public-api": {
"uri": "/apisix/prometheus/metrics"
}
}
}'
```

### Grafana 面板
Expand Down
16 changes: 16 additions & 0 deletions docs/zh/latest/plugins/wolf-rbac.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f1

## 测试插件

#### 为 API 设置路由

我们使用 [public-api](../../../en/latest/plugins/public-api.md) 插件来暴露这些 public API.

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/wal -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/plugin/wolf-rbac/login",
"plugins": {
"public-api": {}
}
}'
```

你也需要为 `change_pwd` 和 `user_info` 两个 API 配置路由。

#### 首先进行登录获取 `wolf-rbac` token:

下面的 `appid`, `username`, `password` 必须为 wolf 系统中真实存在的.
Expand Down