You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/11/30 01:22:13 UTC

[GitHub] [apisix] tokers commented on a diff in pull request #8425: docs: Add new tutorial manage api consumers

tokers commented on code in PR #8425:
URL: https://github.com/apache/apisix/pull/8425#discussion_r1035435995


##########
docs/en/latest/tutorials/manage-api-consumers.md:
##########
@@ -0,0 +1,257 @@
+---
+title: Manage API Consumers
+keywords:
+  - API Gateway
+  - Apache APISIX
+  - Rate Limit
+  - Consumer
+  - Consumer Group
+  - Subscription
+  - Consumer Management
+description: This tutorial explains how to manage your single or multiple API consumers with Apache APISIX.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+This tutorial explains how to manage your single or multiple API consumers with Apache APISIX.
+
+Nowadays [APIs](https://en.wikipedia.org/wiki/API) connect multiple systems, internal services, and third-party applications easily and securely. _API consumers_ are probably the most important stakeholders for API providers because they interact the most with the APIs and the developer portal. This post explains how to manage your single or multiple API consumers with an open-source API Management solution such as [Apache APISIX](https://apisix.apache.org/).
+
+![Manage API Consumers](https://static.apiseven.com/2022/11/29/6385b565b4c11.png)
+
+## API Consumers
+
+API consumers use an API without integrating it into an APP developed for it. In other words, API consumers are _the users of APIs_. This means, for example, a marketing department uses a [Facebook API](https://developers.facebook.com/docs/) to analyze social media responses to specific actions. It does this with individual, irregular requests to the API provided, as needed.
+
+An [API Management](https://en.wikipedia.org/wiki/API_management) solution should know who the consumer of the API is to configure different rules for different consumers.
+
+## Apache APISIX Consumers
+
+In Apache APISIX, the [Consumer object](https://apisix.apache.org/docs/apisix/terminology/consumer/) is the most common way for API consumers to access APIs published through its [API Gateway](https://apisix.apache.org/docs/apisix/terminology/api-gateway/). Consumer concept is extremely useful when you have different consumers requesting the same API and you need to execute various [Plugins](https://apisix.apache.org/docs/apisix/terminology/plugin/) and [Upstream](https://apisix.apache.org/docs/apisix/terminology/upstream/) configurations based on the consumer.

Review Comment:
   By saying different upstream configuration based on the consumer, do you mean consumers can use the traffic-split plugin to change the upstream?



##########
docs/en/latest/tutorials/manage-api-consumers.md:
##########
@@ -0,0 +1,257 @@
+---
+title: Manage API Consumers
+keywords:
+  - API Gateway
+  - Apache APISIX
+  - Rate Limit
+  - Consumer
+  - Consumer Group
+  - Subscription
+  - Consumer Management
+description: This tutorial explains how to manage your single or multiple API consumers with Apache APISIX.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+This tutorial explains how to manage your single or multiple API consumers with Apache APISIX.
+
+Nowadays [APIs](https://en.wikipedia.org/wiki/API) connect multiple systems, internal services, and third-party applications easily and securely. _API consumers_ are probably the most important stakeholders for API providers because they interact the most with the APIs and the developer portal. This post explains how to manage your single or multiple API consumers with an open-source API Management solution such as [Apache APISIX](https://apisix.apache.org/).
+
+![Manage API Consumers](https://static.apiseven.com/2022/11/29/6385b565b4c11.png)
+
+## API Consumers
+
+API consumers use an API without integrating it into an APP developed for it. In other words, API consumers are _the users of APIs_. This means, for example, a marketing department uses a [Facebook API](https://developers.facebook.com/docs/) to analyze social media responses to specific actions. It does this with individual, irregular requests to the API provided, as needed.
+
+An [API Management](https://en.wikipedia.org/wiki/API_management) solution should know who the consumer of the API is to configure different rules for different consumers.
+
+## Apache APISIX Consumers
+
+In Apache APISIX, the [Consumer object](https://apisix.apache.org/docs/apisix/terminology/consumer/) is the most common way for API consumers to access APIs published through its [API Gateway](https://apisix.apache.org/docs/apisix/terminology/api-gateway/). Consumer concept is extremely useful when you have different consumers requesting the same API and you need to execute various [Plugins](https://apisix.apache.org/docs/apisix/terminology/plugin/) and [Upstream](https://apisix.apache.org/docs/apisix/terminology/upstream/) configurations based on the consumer.
+
+By publishing APIs through **Apache APISIX API Gateway**, you can easily secure API access using consumer keys or sometimes it can be referred to as subscription keys. Developers who need to consume the published APIs must include a valid subscription key in `HTTP` requests when calling those APIs. Without a valid subscription key, the calls are rejected immediately by the API gateway and not forwarded to the back-end services.
+
+Consumers can be associated with various scopes: per Plugin, all APIs, or an individual API. There are many use cases for consumer objects in the API Gateway that you get with the combination of its plugins:
+
+1. Enable different authentication methods for different consumers.

Review Comment:
   I think for this feature, it's worthy saying why I need this.



##########
docs/en/latest/tutorials/manage-api-consumers.md:
##########
@@ -0,0 +1,257 @@
+---
+title: Manage API Consumers
+keywords:
+  - API Gateway
+  - Apache APISIX
+  - Rate Limit
+  - Consumer
+  - Consumer Group
+  - Subscription
+  - Consumer Management
+description: This tutorial explains how to manage your single or multiple API consumers with Apache APISIX.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+This tutorial explains how to manage your single or multiple API consumers with Apache APISIX.
+
+Nowadays [APIs](https://en.wikipedia.org/wiki/API) connect multiple systems, internal services, and third-party applications easily and securely. _API consumers_ are probably the most important stakeholders for API providers because they interact the most with the APIs and the developer portal. This post explains how to manage your single or multiple API consumers with an open-source API Management solution such as [Apache APISIX](https://apisix.apache.org/).
+
+![Manage API Consumers](https://static.apiseven.com/2022/11/29/6385b565b4c11.png)
+
+## API Consumers
+
+API consumers use an API without integrating it into an APP developed for it. In other words, API consumers are _the users of APIs_. This means, for example, a marketing department uses a [Facebook API](https://developers.facebook.com/docs/) to analyze social media responses to specific actions. It does this with individual, irregular requests to the API provided, as needed.
+
+An [API Management](https://en.wikipedia.org/wiki/API_management) solution should know who the consumer of the API is to configure different rules for different consumers.
+
+## Apache APISIX Consumers
+
+In Apache APISIX, the [Consumer object](https://apisix.apache.org/docs/apisix/terminology/consumer/) is the most common way for API consumers to access APIs published through its [API Gateway](https://apisix.apache.org/docs/apisix/terminology/api-gateway/). Consumer concept is extremely useful when you have different consumers requesting the same API and you need to execute various [Plugins](https://apisix.apache.org/docs/apisix/terminology/plugin/) and [Upstream](https://apisix.apache.org/docs/apisix/terminology/upstream/) configurations based on the consumer.
+
+By publishing APIs through **Apache APISIX API Gateway**, you can easily secure API access using consumer keys or sometimes it can be referred to as subscription keys. Developers who need to consume the published APIs must include a valid subscription key in `HTTP` requests when calling those APIs. Without a valid subscription key, the calls are rejected immediately by the API gateway and not forwarded to the back-end services.
+
+Consumers can be associated with various scopes: per Plugin, all APIs, or an individual API. There are many use cases for consumer objects in the API Gateway that you get with the combination of its plugins:
+
+1. Enable different authentication methods for different consumers.
+2. Restrict access to API resources for specific consumers.
+3. Route requests to the corresponding backend service based on the consumer.
+4. Define rate limiting on the number of data clients can consume.
+5. Analyze data usage for an individual and a subset of consumers.
+
+## Apache APISIX Consumer example.
+
+Let's look at some examples of configuring the rate-limiting policy for a single consumer and a group of consumers with the help of [key-auth](https://apisix.apache.org/docs/apisix/plugins/key-auth/) authentication key (API Key) and [limit-count](https://apisix.apache.org/docs/apisix/plugins/limit-count/) plugins. For the demo case,  we can leverage [the sample project](https://github.com/Boburmirzo/apisix-api-consumers-management) built on [ASP.NET Core WEB API](https://learn.microsoft.com/en-us/aspnet/core/?view=aspnetcore-7.0) with a single `GET` endpoint (retrieves all products list). You can find in [README file](https://github.com/Boburmirzo/apisix-api-consumers-management#readme) all instructions on how to run the sample app.
+
+### Enable rate-limiting for a single consumer
+
+Up to now, I assume that the sample project is up and running. To use consumer object along with the other two plugins we need to follow easy steps:
+
+- Create a new Consumer.
+- Specify the authentication plugin key-auth and limit count for the consumer.
+- Create a new Route, and set a routing rule (If necessary).
+- Enable key-auth plugin configuration for the created route.
+
+The above steps can be achieved by running simple two [curl commands](https://en.wikipedia.org/wiki/CURL) against APISIX [Admin API](https://apisix.apache.org/docs/apisix/admin-api/).
+
+The first `cmd` creates a **new Consumer** with API Key based authentication enabled where the API consumer can only make 2 requests against the Product API within 60 seconds.
+
+``` shell
+curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+   "username":"consumer1",
+   "plugins":{
+      "key-auth":{
+         "key":"auth-one"
+      },
+      "limit-count":{
+         "count":2,
+         "time_window":60,
+         "rejected_code":403,
+         "rejected_msg":"Requests are too many, please try again later or upgrade your subscription plan.",
+         "key":"remote_addr"
+      }
+   }
+}'
+```
+
+Then, we define our **new Route and Upstream** so that all incoming requests to the gateway endpoint `/api/products` will be forwarded to our example product backend service after a successful authentication process.
+
+``` shell
+curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+  "name": "Route for consumer request rate limiting",
+  "methods": [
+    "GET"
+  ],
+  "uri": "/api/products",
+    "plugins": {
+        "key-auth": {}
+    },
+  "upstream": {
+    "type": "roundrobin",
+    "nodes": {
+      "productapi:80": 1
+    }
+  }
+}'
+```
+
+Apache APISIX will handle the first two requests as usual, but a third request in the same period will return a `403 HTTP` code.

Review Comment:
   ```suggestion
   Apache APISIX will handle the first two requests as usual, but a third request in the same period will return a `403` HTTP code.
   ```



##########
docs/en/latest/tutorials/manage-api-consumers.md:
##########
@@ -0,0 +1,257 @@
+---
+title: Manage API Consumers
+keywords:
+  - API Gateway
+  - Apache APISIX
+  - Rate Limit
+  - Consumer
+  - Consumer Group
+  - Subscription
+  - Consumer Management
+description: This tutorial explains how to manage your single or multiple API consumers with Apache APISIX.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+This tutorial explains how to manage your single or multiple API consumers with Apache APISIX.
+
+Nowadays [APIs](https://en.wikipedia.org/wiki/API) connect multiple systems, internal services, and third-party applications easily and securely. _API consumers_ are probably the most important stakeholders for API providers because they interact the most with the APIs and the developer portal. This post explains how to manage your single or multiple API consumers with an open-source API Management solution such as [Apache APISIX](https://apisix.apache.org/).
+
+![Manage API Consumers](https://static.apiseven.com/2022/11/29/6385b565b4c11.png)
+
+## API Consumers
+
+API consumers use an API without integrating it into an APP developed for it. In other words, API consumers are _the users of APIs_. This means, for example, a marketing department uses a [Facebook API](https://developers.facebook.com/docs/) to analyze social media responses to specific actions. It does this with individual, irregular requests to the API provided, as needed.
+
+An [API Management](https://en.wikipedia.org/wiki/API_management) solution should know who the consumer of the API is to configure different rules for different consumers.
+
+## Apache APISIX Consumers
+
+In Apache APISIX, the [Consumer object](https://apisix.apache.org/docs/apisix/terminology/consumer/) is the most common way for API consumers to access APIs published through its [API Gateway](https://apisix.apache.org/docs/apisix/terminology/api-gateway/). Consumer concept is extremely useful when you have different consumers requesting the same API and you need to execute various [Plugins](https://apisix.apache.org/docs/apisix/terminology/plugin/) and [Upstream](https://apisix.apache.org/docs/apisix/terminology/upstream/) configurations based on the consumer.
+
+By publishing APIs through **Apache APISIX API Gateway**, you can easily secure API access using consumer keys or sometimes it can be referred to as subscription keys. Developers who need to consume the published APIs must include a valid subscription key in `HTTP` requests when calling those APIs. Without a valid subscription key, the calls are rejected immediately by the API gateway and not forwarded to the back-end services.
+
+Consumers can be associated with various scopes: per Plugin, all APIs, or an individual API. There are many use cases for consumer objects in the API Gateway that you get with the combination of its plugins:
+
+1. Enable different authentication methods for different consumers.
+2. Restrict access to API resources for specific consumers.
+3. Route requests to the corresponding backend service based on the consumer.
+4. Define rate limiting on the number of data clients can consume.
+5. Analyze data usage for an individual and a subset of consumers.
+
+## Apache APISIX Consumer example.

Review Comment:
   ```suggestion
   ## Apache APISIX Consumer example
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org