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/12/15 07:58:51 UTC

[GitHub] [apisix] Boburmirzo commented on a diff in pull request #8522: docs: Add new tutorial for managing multiple API version

Boburmirzo commented on code in PR #8522:
URL: https://github.com/apache/apisix/pull/8522#discussion_r1049317750


##########
docs/en/latest/tutorials/add-multiple-api-versions.md:
##########
@@ -0,0 +1,227 @@
+---
+title: Add multiple API versions
+keywords:
+  - API Versioning
+  - Multiple APIs
+  - Proxy rewrite
+  - Request redirect
+  - Route API requests
+description: In this tutorial, you will learn how to _publish and manage multiple versions of your API_ 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.
+#
+-->
+
+## What is API versioning?
+
+**API versioning** is the practice of managing changes to an API and ensuring that these changes are made without disrupting clients. A good API versioning strategy clearly communicates the changes made and allows API consumers to decide when to upgrade to the latest version at their own pace.
+
+## Types of API Versioning
+
+#### URI Path
+
+The most common way to version an API is in the URI path and is often done with the prefix "v". This method employs URI routing to direct requests to a specific version of the API.
+
+```shell
+http://org.apisix/v1/hello
+http://org.apisix/v2/hello
+```
+
+#### Query Params
+
+In this method, the version number is included in the URI, but as a query parameter instead of in the path.
+
+```shell
+http://org.apisix/hello?version=1
+http://org.apisix/hello?version=2
+```
+
+#### Custom Request Header
+
+You can also set the version number using custom headers in requests and responses. This leaves the URI of your resources unchanged.
+
+```shell
+http://org.apisix/hello -H 'Version: 1'
+http://org.apisix/hello -H 'Version: 2'
+```
+
+The primary goal of versioning is to provide users of an API with the most functionality possible while causing minimal inconvenience. Keeping this goal in mind, let’s have a look in this tutorial at how to _publish and manage multiple versions of your API_ with Apache APISIX.
+
+**In this tutorial**, you learn how to:
+
+- Create a route and upstream for our sample API.
+- Add a new version to the existing API.
+- Use [proxy-rewrite](https://apisix.apache.org/docs/apisix/plugins/proxy-rewrite/) plugin to rewrite the path in a plugin configuration.
+- Route API requests from the old version to the new one.
+
+## Prerequisites
+
+For the demo case, we will leverage the sample repository [Evolve APIs](https://github.com/nfrankel/evolve-apis) on GitHub built on the Spring boot that demonstrates our API. You can see the complete source code there.
+
+To execute and customize the example project per your need shown in this tutorial, here are the minimum requirements you need to install in your system:
+
+- [Docker Desktop](https://docs.docker.com/desktop/windows/install/) - you need [Docker desktop](https://www.docker.com/products/docker-desktop/) installed locally to complete this tutorial. It is available for [Windows](https://desktop.docker.com/win/edge/Docker%20Desktop%20Installer.exe) or [macOS](https://desktop.docker.com/mac/edge/Docker.dmg).
+
+Also, complete the following steps to run the sample project with Docker.
+
+Use [git](https://git-scm.com/downloads) to clone the repository:
+
+``` shell
+git clone 'https://github.com/nfrankel/evolve-apis'
+```
+
+Go to root directory of _evolve-apis_
+
+``` shell
+cd evolve-apis
+```
+
+Now we can start our application by running `docker compose up` command from the root folder of the project:
+
+``` shell
+docker compose up -d
+```
+
+### Create a route and upstream for the API.
+
+You first need to [route](https://apisix.apache.org/docs/apisix/terminology/route/) your HTTP requests from the gateway to an [upstream](https://apisix.apache.org/docs/apisix/terminology/upstream/) (your API). With APISIX, you can create a route by sending an HTTP request to the gateway.
+
+```shell
+curl http://apisix:9080/apisix/admin/routes/1 -H 'X-API-KEY: xyz' -X PUT -d '
+{
+  "name": "Direct Route to Old API",
+  "methods": ["GET"],
+  "uris": ["/hello", "/hello/", "/hello/*"],
+  "upstream": {
+    "type": "roundrobin",
+    "nodes": {
+      "oldapi:8081": 1
+    }
+  }
+}'
+```
+
+At this stage, we do not have yet any version and you can query the gateway as below:
+
+```shell
+> curl http://org.apisix/hello

Review Comment:
   Good suggestion! Fixed it. Thanks!



-- 
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