Skip to main content

Version: 3.2.14.3

Publish Service Version

For version control of deployed APIs, leverage API7 Gateway for publishing service versions to different gateway groups, instead of in-place gateway group edits.

Typically, an API version is published first in test and staging environments before publishing in production environments. API7 Gateway manages this environmental separation through Gateway Groups, where an API belongs to a single Published Service with a shared Upstream.

This tutorial guides you in publishing the httpbin service to a gateway group on API7 Gateway. You will learn how to:

  1. Create a service manually and through an OpenAPI Specification file.
  2. Publish services by configuring upstream nodes and by using service discovery mechanisms.

Prerequisites

  1. Install API7 Enterprise.
  2. Have at least one gateway instance in your gateway group.

Add a Service Template with Routes

You can either use the dashboard or ADC to add a service manually.

  1. Select Service Hub from the side navigation bar, then click Add Service.
  2. Select Add Manually.
  3. From the dialog box, do the following:
  • In the Name field, enter httpbin.
  • In the Service Type field, choose HTTP(Layer 7 Proxy).
  • In the Upstream Scheme field, choose HTTP.
  • Click Add.
  1. Inside the service, click Add Route.
  2. From the Add Route dialog box, do the following:
  • In the Name field, enter getting-started-anything.
  • In the Path field, enter /anything/*.
  • In the Methods field, choose GET.
  • Click Add.

Publish the Service to Gateway Group

You can either use the dashboard or ADC to publish a service.

  1. Select Service Hub from the side navigation bar and then select httpbin.
  2. Click Publish New Version.
  3. Select your target gateway group, for example, default, and then click Next.
  4. From the dialog box, do the following:
  • In the New Version field, enter 1.0.0.
  • In the How to find the upstream field, choose Use Nodes.
  • Click Add Node. From the dialog box, do the following:
    • In the Host and Port fields, enter httpbin.org as the host and 80 as the port.
    • In the Weight field, use the default value 100.
    • Click Add.
  • Confirm the service information and then click Publish.

Below is an interactive demo that provides a hands-on introduction to publish versioned services. You will gain a better understanding of how to use it in API7 Enterprise by clicking and following the steps.

Publish the Service Using Service Discovery

Instead of configuring the upstream directly, service discovery mechanisms like Consul, Eureka, Nacos, or Kubernetes Service Discovery can be used to dynamically detect upstream nodes.

info

Once published, a service cannot directly switch between configured upstream nodes and service discovery. Instead, you have to configure this through a canary deployment.

  1. Select Service Registries of your gateway group from the side navigation bar, then click Add Service Registry Connection.
  2. From the dialog box, do the following:
  • In the Name field, enter Registry for Test.
  • In the Discovery Type field, choose Kubernetes.
  • Fill in the API Server Address and Token Value field.
  • Click Add.
  1. Wait to make sure the status of the service registry is Healthy.
  2. Select Service Hub from the side navigation bar, then click Publish New Version for the httpbin service.
  3. Choose your target gateway group, for example, default, then click Next.
  4. From the dialog box, do the following:
  • In the New Version field, enter 1.0.0.
  • In the How to find the upstream field, choose Use Service Discovery.
  • In the Service Registry field, choose Registry for Test, then choose the Namespace and Service Name.
  • Confirm the service information, then click Publish.

Below is an interactive demo that provides a hands-on introduction to connecting Kubernetes service discovery. You will gain a better understanding of how to use it in API7 Gateway by clicking and following the steps.

Validate the API

curl "http://127.0.0.1:9080/anything/publish"

You should see the following output:

{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Host": "localhost",
"User-Agent": "curl/7.88.1",
"X-Amzn-Trace-Id": "Root=1-664cc6d6-10fe9f740ab1629e19cf85a2",
"X-Forwarded-Host": "localhost"
},
"json": null,
"method": "GET",
"origin": "152.15.0.1, 116.212.249.196",
"url": "http://localhost/anything/publish"
}

Additional Resources


API7.ai Logo

API Management for Modern Architectures with Edge, API Gateway, Kubernetes, and Service Mesh.

Product

API7 Cloud

SOC2 Type IRed Herring

Copyright © APISEVEN Ltd. 2019 – 2024. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the

Apache Software Foundation