Skip to main content

Version: 3.2.9.5

Publish APIs by Service

After your APIs are designed, developed, and deployed, you can use API7 Enterprise to publish them.

Typically, APIs are published first in test and staging environments before publishing in production environments. API7 Enterprise manages this separation through Gateway Groups, where an API is a Service with a shared Upstream.

This tutorial guides you in publishing the httpbin API to a test environment on API7 Enterprise. 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 and complete the Launch Your First API tutorial.
  2. Rename the default gateway group to Test Group and configure the network. Test Group will be the API gateway for your test environment.
  3. Have at least one Gateway Instance in the Test Group.

Add a Service with Routes

  1. Select Services from the side navigation bar, then click Add Service.
  2. Select Add Manually.
  3. In the Name field, enter httpbin API.
  4. Click Add.
  5. Inside the service, click Add Route.
  6. From the Add Route dialog box, do the following:
    1. In the Name field, enter getting-started-anything.
    2. In the Path field, enter /anything/*.
    3. In the Methods field, choose GET.
  7. Click Add.

Publish the Service Using Upstream Nodes

  1. Select Services from the side navigation bar and then select httpbin API.
  2. Click Publish Now.
  3. Select Test Group 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 your backend node address in the test environment. For this tutorial, use httpbin.org as the host and 80 as the port.
      • In the Weight field, use the default value 100.
      • Click Add.
  5. Confirm the service information and then click Publish.

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 Gateway Groups from the side navigation bar, then choose Test Group.
  2. Select Service Registries from the side navigation bar and then click Add Service Registry Connection.
  3. From the Add Route dialog box, do the following:
    1. In the Name field, enter Registry for Test.
    2. In the Discovery Type field, choose Kubernetes.
    3. Fill in the API Server Address and Token Value field.
    4. Click Add.
  4. Wait to make sure the status of the service registry is Healthy.
  5. Select Services from the side navigation bar, then click Publish Now for the httpbin API service.
  6. Choose the Test Group gateway group and then click Next.
  7. From the Publish dialog box, do the following:
    1. In the New Version field, enter 1.0.0.
    2. In the How to find the upstream field, choose Use Service Discovery.
    3. In the Service Registry field, choose Registry for Test, then choose the Namespace and Service Name.
    4. Confirm the service information, then click Publish.

Use ADC to Publish the API

Alternatively, use ADC to configure API7 Enterprise declaratively instead of the dashboard. The complete configuration is below:

adc.yaml
services:
- name: httpbin API
upstream:
name: default
scheme: http
nodes:
- host: httpbin.org
port: 80
weight: 100
routes:
- uris:
- /anything/*
name: getting-started-anything
description: Return anything that is passed in on the request.
methods:
- GET

Synchronize the configuration to API7 Enterprise:

adc sync -f adc.yaml

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

API7.ai Logo

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

Product

API7 Cloud

SOC2 Type IIISO 27001HIPAAGDPRRed Herring

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

Apache Software Foundation