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:
- Create a service manually and through an OpenAPI Specification file.
- Publish services by configuring upstream nodes and by using service discovery mechanisms.
Prerequisites
- Install API7 Enterprise.
- Have at least one gateway instance in your gateway group.
Add a Service Template with Routes
Add Manually
- Dashboard
- ADC
- Select Service Hub from the side navigation bar, then click Add Service.
- Select Add Manually.
- 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.
- Inside the service, click Add Route.
- 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.
Create an ADC configuration file with the service its upstream and route configuration:
services:
- name: httpbin
upstream:
name: httpbin upstream
scheme: http
nodes:
- host: httpbin.org
port: 80
weight: 100
routes:
- uris:
- /anything/*
name: getting-started-anything
methods:
- GET
Import OpenAPI Specification
Both the dashboard and ADC support importing an OpenAPI v3.0 Specification.
Define your API in a YAML/JSON file as shown below:
openapi: 3.1.0
info:
title: httpbin
description: "httpbin for the API7 Enterprise Getting Started guides."
version: 1.0.0
paths:
"/anything/*":
get:
tags:
- Anything
summary: Returns anything that is passed into the request.
operationId: getting-started-anything
responses:
"200":
description: Successful Response
content:
application/json:
schema:
type: string
tags:
- name: Anything
description: Return anything that is passed in on the request.
Then, use it in API7 Gateway:
- Dashboard
- ADC
- Select Service Hub from the side navigation bar, then click Add Service.
- Select Import OpenAPI.
- From the dialog box, do the following:
- Upload your YAML/JSON file.
- In the Upstream Scheme field, choose
HTTP
. - Click Next.
- Confirm the following information:
- Name: the
title
field in OpenAPI Specification. - Labels: the
tag
field in OpenAPI Specification. - Description: the
description
field in OpenAPI Specification. - Routes: the
Paths
field in OpenAPI Specification. - Click Add.
Use ADC to convert the OpenAPI Specification to an ADC configuration file:
adc convert openapi -f openapi.yaml -o adc.yaml
Publish Single Service to Gateway Group
- Dashboard
- ADC
- Select Service Hub from the side navigation bar and then select
httpbin
. - Click Publish New Version.
- Select your target gateway group, for example,
default
, and then click Next. - 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 and80
as the port. - In the Weight field, use the default value
100
. - Click Add.
- In the Host and Port fields, enter
- Confirm the service information and then click Publish.
Synchronize the configuration file created in the previous step to your target gateway group, for example, default
:
adc sync -f adc.yaml --gateway-group default
Publish Multiple Services to Gateway Group
- Dashboard
- ADC
- Select Service Hub from the side navigation bar and then click Batch Publish Services.
- Select your target gateway group, for example,
default
, and then click Next. - Click Add Service.
- From the dialog box, do the following:
- In the Service dropdown, select the service you want to publish.
- In the New Version field, enter
1.0.0
. - Click Add.
- Repeat the above steps to add more services.
- Click Next to continue publishing the services.
- In the new window, do the following for each service:
- 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 and80
as the port. - In the Weight field, use the default value
100
. - Click Add.
- In the Host and Port fields, enter
- Confirm the information and then click Publish.
To publish multiple services, you can either update your ADC configuration file to include other services or use multiple configuration files and synchronize them to your target gateway group, for example, default
, as shown below:
adc sync -f adc-1.yaml -f adc-2.yaml
Below is an interactive demo that provides a hands-on introduction to publishing versioned services. You will gain a better understanding of how to use it in API7 Enterprise 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
- Key Concepts
- Getting Started
- Best Practices