Skip to main content

Version: 3.2.10.1

Publish APIs by Service

After designing, developing, and deploying APIs, you can publish them in API7 Enterprise for accessibility. You can publish to test, staging, and production environments, or to multiple regions. Since APIs are typically organized by backend service, they are managed by service in API7 Enterprise. The APIs for a particular backend share upstream configurations and get updated together when backend changes occur.

This tutorial describes how to publish Swagger Petstore APIs to a mocked test environment.

Prerequisites

  1. Install API7 Enterprise.
  2. Obtain a user account with Super Admin or API Provider role.
  3. Rename the default gateway group to Test Group and configure the network. This gateway group acts as the API gateway for your test environment.
  4. Add at least one gateway instance in the Test Group.

Add Service and Its Routes

  1. Select Services from the side navigation bar, then click Add Service.
  2. Select Add Manually.
  3. In the Name field, enter Swagger Petstore.
  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 getPetById.
    2. In the Path field, enter /pet/*.
    3. In the Methods field, choose GET.
  7. Click Add.

Publish Service Using Upstream Nodes

  1. Select Services from the side navigation bar and then select Swagger Petstore.
  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 or the mock server address.
      • In the Weight field, use the default value 100.
      • Click Add.
  5. Confirm the service information and then click Publish.

Publish Service Using Service Discovery

Service discovery mechanisms like Consul, Eureka, Nacos or Kubernetes Service Discovery can be used to dynamically detect upstream nodes.

info

After publishing, a service cannot directly switch between using defined upstream nodes vs using service discovery. However, switching between upstream nodes and service discovery can be done through canary.

  1. Select Gateway Groups from the side navigation bar, then choose Test Group.
  2. Select Service Registries from the side navigation bar and then clickAdd 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 Valuefield.
    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 Swagger Petstore 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.

Validate APIs

curl "http://127.0.0.1:9080/pet/1"  

You should see the following output:

{
"name": "Dog",
"photoUrls": [
"https://example.com/dog-1.jpg",
"https://example.com/dog-2.jpg"
],
"id": 1,
"category": {
"id": 1,
"name": "pets"
},
"tags": [
{
"id": 1,
"name": "friendly"
},
{
"id": 2,
"name": "smart"
}
],
"status": "available"
}

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