In this section, you’ll be adding an API to Kong. In order to do this, you’ll
first need to add a Service; that is the name Kong uses to refer to the upstream APIs and microservices
For the purpose of this guide, we’ll create a Service pointing to the Mockbin API. Mockbin is
an “echo” type public website which returns the requests it gets back to the requester, as responses. This
makes it helpful for learning how Kong proxies your API requests.
Before you can start making requests against the Service, you will need to add a Route to it.
Routes specify how (and if) requests are sent to their Services after they reach Kong. A single
Service can have many Routes.
After configuring the Service and the Route, you’ll be able to make requests through Kong using them.
Kong exposes a RESTful Admin API on port :8001. Kong’s configuration, including adding Services and
Routes, is made via requests on that API.
1. Add your Service using the Admin API or GUI
If you’d like to use the Admin API, issue the following cURL request to add
your first API (Mockbin) to Kong Enterprise:
$ curl -i-X POST \--url http://localhost:8001/services/ \--data'name=example-service'\--data'url=http://mockbin.org'
After adding your Service, add a Route linked to it:
$ curl -i-X POST \--url http://localhost:8001/services/example-service/routes \--data'hosts=example.com'
Or, add your first API in the Admin GUI, via Services & Routes:
Kong is now aware of your Service and ready to proxy requests.
2. Verify that your API has been added
You’ll get a confirmation message in the Admin GUI, or if you used cURL
you should see responses similar to the following:
Kong is now aware of your API and ready to proxy requests.
3. Forward your requests through Kong EE
Issue the following cURL request to verify that Kong is properly forwarding
requests to your API. 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 upstream_url we configured in step #1,
and is forwarding the response back to us. Kong knows to do this through
the header defined in the above cURL request Host: example.com
Now that you’ve added your API to Kong EE, let’s learn how to enable plugins.