Launch Your First API
This tutorial describes launching and validating a simple API on API7 Enterprise. You will complete the following steps:
- Create a Published Service with a Route and an Upstream that points to
httpbinupstream. - Validate the created API by sending a request.
Prerequisites
- Install API7 Enterprise.
- Follow the Docker instruction in Add a Gateway Instance to deploy a gateway instance.
Create Service and Route
- Dashboard
- ADC
Create a Service
- Select Published Services under your gateway group from the side navigation bar and then click Add Service.
- Select Add Manually.
- From the Add Service 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. - In the How to find the upstream field, choose
Use Nodes. - Click Add Node.
- From the Add Node dialog box, do the following:
- In the Host field, enter
httpbin.org. - In the Port field, enter
80. - In the Weight field, enter
100.
- In the Host field, enter
- In the Name field, enter
- Click Add. This will create a new service in the 'No Version' state.
Create a Route
- Click the service that you just created in the previous step, and then click Add Route.
- From the Add Route dialog box, do the following:
- In the Name field, enter
get-ip. - In the Path field, enter
/ip. - In the Methods field, choose
GET. - Click Add.
- In the Name field, enter
Below is an interactive demo that provides a hands-on introduction to creating no-version services. You will better understand how to use it in API7 Enterprise by clicking and following the steps.
Create the following configuration file:
services:
- name: httpbin
upstream:
name: default
scheme: http
nodes:
- host: httpbin.org
port: 80
weight: 100
routes:
- uris:
- /ip
name: get-ip
methods:
- GET
Synchronize the configuration to API7 Enterprise:
adc sync -f adc.yaml
Validate the API
In the dashboard, you should see a new service created under the Published Services.
- Dashboard
- ADC
Send a request to the route:
curl "http://127.0.0.1:9080/ip"
You should see the following response:
{
"origin": "127.0.0.1"
}
Send a request to the route:
curl "http://127.0.0.1:9080/ip"
You should see the following response:
{
"origin": "127.0.0.1"
}
And that’s it. You have your first API running now.
Add APIs by Importing OpenAPI
You can also add APIs by importing OpenAPI 3.0 specification. To create a Service:
- Select Published Services under your gateway group from the side navigation bar and then click Add Service.
- Select Import OpenAPI.
- From the Add Service dialog box, do the following:
- In the OpenAPI 3.0 Specification field, upload the
httpbin.yamlfile. - In the Upstream Scheme and Service Type fields, keep the default settings
HTTP. - In the How to find the upstream field, keep the default setting
Use Nodes. - Click Add Node.
- From the Add Node dialog box, do the following:
- In the Host field, enter
httpbin.org. - In the Port field, enter
80. - In the Weight field, enter
100.
- In the Host field, enter
- Click Next.
- In the OpenAPI 3.0 Specification field, upload the
- Click Add. This will create a new service in the 'No Version' state. The basic information and labels are imported, and all paths in the openapi file are transformed to routes in the service.
Below is an interactive demo that provides a hands-on introduction to adding services by importing OpenAPI. You will better understand how to use it in API7 Enterprise by clicking and following the steps.
Additional Resources
- Getting Started
- Best Practices