Add your API to Konnect
If you used the in-app onboarding wizard when you logged in to Konnect for the first time, you should already have a demo service.
In this guide, you will build on your Konnect environment by adding your own API to Konnect using services and routes.
What are services and routes?
Services: A service is an entity representing an external upstream API or microservice. For example, a data transformation microservice, a billing API, and so on.
Routes: Routes determine how (and if) requests are sent to their services after they reach the gateway. Where a service represents the backend API, a route defines what is exposed to clients. A single service can have many routes. Once a route is matched, the gateway proxies the request to its associated service.
Prerequisites
Add your API
-
In the Gateway Manager, select the Default control plane.
-
Select Gateway Services from the side navigation bar, then New Gateway Service.
-
From the Add a Gateway Service dialog, create a new service:
-
Enter a unique name for the Gateway service, or specify a Gateway service that doesn’t yet have a version connected to it.
For the purpose of this example, enter example_gateway_service
.
The name can be any string containing letters, numbers, or the following characters: .
, -
, _
, ~
, or :
. Do not use spaces.
For example, you can use example_service
, ExampleService
, Example-Service
. However, Example Service
is invalid.
-
In the Upstream URL field, enter https://httpbin.konghq.com
.
-
Use the defaults for the remaining fields.
-
Click Save.
-
Add a route to your service implementation by clicking the Add a Route button now visible from the Gateway service dashboard.
For this example, enter the following:
-
Name:
httpbin
-
Protocols:
HTTP
, HTTPS
-
Path(s):
/mock
-
Click Save.
The Konnect API uses Personal Access Token (PAT) authentication. You can obtain your PAT from the personal access token page. The PAT must be passed in the Authorization
header of all requests.
- Get the list of all control planes so you can copy the control plane ID associated with the
default
control plane:
curl --request GET \
--url https://us.api.konghq.com/v2/control-planes \
--header 'Authorization: Bearer <personal-access-token>' \
--header 'accept: application/json'
In this guide, we will assign your service to the default
control plane for the sake of simplicity.
-
Create a service for your API that is assigned to the
default
control plane:
curl --request POST \
--url https://{region}.api.konghq.com/v2/control-planes/{defaultControlPlaneId}/core-entities/services \
--header 'Authorization: Bearer <personal-access-token>' \
--header 'Content-Type: application/json' \
--header 'accept: application/json' \
--data '{
"name": "my_service",
"host": "httpbin.konghq.com",
"path": "/mock"
}'
This service represents your backend API. Be sure to replace the PAT as well as the following placeholders with your own values:
-
defaultControlPlaneId
: The ID of the default control plane. This associates the service with that control plane.
-
name
: The name you want to display for your service.
-
host
: The host of the upstream server. This is case sensitive.
-
path
: The path to be used in requests to the upstream server.
Be sure to save the service ID from the response to use it in the next step.
-
Add a route to your service:
curl --request POST \
--url https://{region}.api.konghq.com/v2/control-planes/{defaultControlPlaneId}/core-entities/routes \
--header 'Authorization: Bearer <personal-access-token>' \
--header 'Content-Type: application/json' \
--header 'accept: application/json' \
--data '{
"name": "my_route",
"hosts": [
"httpbin.konghq.com"
],
"paths": [
"/mock"
],
"service": {
"id": "49248arf-b90c-4c0b-9529-3a949dfc10d1"
}
}'
This route defines what is exposed to clients. Be sure to replace the PAT as well as the following placeholders with your own values:
-
defaultControlPlaneId
: The ID of the default control plane. This associates the service with that control plane.
-
name
: The name you want to display for your route.
-
host
: A list of domain names that match this route. This is case sensitive.
-
path
: A list of paths that match this route.
-
"service": "id"
: The ID of the service you created in the previous step. This should be part of the response from the previous request.
Verify the implementation
If you used the Docker script to connect a data plane
earlier, your default proxy URL is localhost:8000
.
Enter the proxy URL into your browser’s address bar and append the route path
you just set. The final URL should look something like this:
http://localhost:8000/mock
If successful, you should see the homepage for httpbin.konghq.com
. In the Gateway Manager you will now see a 200 responses recorded in the Analytics tab.
And that’s it! You have your first service set up, running, and routing
traffic proxied through a Kong Gateway data plane node.
Important: To conserve your free trial credits, delete any APIs you don’t plan to use in production.
Next steps
Now that you’ve added your API to Konnect, you can continue to test Konnect’s capabilities: