Add a Service and Route
Introduction
This guide walks through the creation and configuration of a Service and Route via Kong Manager in Kong Enterprise.
For the purpose of this guide, we’ll create a Service pointing to the Mockbin API. Mockbin is an “echo” type public website that returns requests back to the requester as responses. This visibility is helpful for learning how Kong proxies API requests.
Kong exposes the RESTful Admin API on port :8001
. Kong’s configuration,
including adding Services and Routes, is made via requests on to the
Admin API.
Prerequisites
enforce_rbac = on
- Kong Enterprise has started
- Logged in to Kong Manager as a Super Admin
Step 1 - Create a New Service
-
Chose the desired Workspace in Kong Manager and navigate to the Services tab under API Gateway.
-
Click the Create a New Service button to open the Create Service form. Fill in a name and a URL for the Service.
For example, set the name totest-service
with the URLhttp://mockbin.org
.
Kong Manager also allows Services to be configured using Protocol, Host, Path, and Port (optional). To configure the Service using this method, click the Add using Protocol, Host, and Path option.
In addition, Kong Manager exposes several Advanced Fields and their default configuration values:Retries: 5
Connect Timeout: 60000
(in ms)Write Timeout: 60000
(in ms)
Read Timeout: 60000
(in ms)
Adjusting these values is optional and can be edited later. -
Create the Service by clicking the Create Service button at the bottom of the form.
If successful, you will be automatically redirected to the Service’s Overview page.
The Service Overview page displays information and Activity on the Service, as well as any Routes or Plugins that have been connected to the Service.
Step 2 - Create a New Route attached to the Service
-
From the Service Overview page accessed in Step 1, click the Create New Route button located in the Routes tab at the bottom of the page.
-
To create a Route you must provide the Service
name
andid
, this will be automatically filled out if the form was accessed via the Service Overview page.
If this field is not automatically filled, the Service Id can be found via the Services Overview page, accessed by clicking on the Services tab on the side navigation and then clicking the clipboard icon next to the desired Service’s Id field. -
The Route will also need a name, and at least one of the following fields: Host, Methods, or Paths
To continue with the Mockbin example, name the Routetest-route
with the Hostexample.com
. Once completed, click the Create Route button at the bottom of the form. -
If created successfully, the page will be automatically redirected back to the Service Overview page, and the new Route will now appear under the Routes tab.
Step 3 - Test the new Service and Route
Issue the following cURL request to verify that Kong is properly forwarding
requests to the Service. Note that by default Kong handles proxy requests on
port :8000
:
$ curl -i -X GET \
--url http://localhost:8000/ \
--header 'Host: example.com'
A successful response means Kong is now forwarding requests made to http://localhost:8000 to the Service URL configured in Step 1, and is forwarding the response back. Kong knows to do this through the header defined in the above cURL request.