Maybe you were looking for the Enterprise Documentation instead?
Careful! You are browsing documentation for an outdated version of Kong. Go here to browse the documentation for the latest version.

Table of Contents

Before you start:
  1. Make sure you've installed Kong — It should only take a minute!
  2. Make sure you've started Kong.

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 it manages.

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

Issue the following cURL request to add your first Service (pointing to the Mockbin API) to Kong:

$ curl -i -X POST \
  --url http://localhost:8001/services/ \
  --data 'name=example-service' \
  --data 'url='

You should receive a response similar to:

HTTP/1.1 201 Created
Content-Type: application/json
Connection: keep-alive


Back to TOC

2. Add a Route for the Service

$ curl -i -X POST \
  --url http://localhost:8001/services/example-service/routes \
  --data 'hosts[]'

The answer should be similar to:

HTTP/1.1 201 Created
Content-Type: application/json
Connection: keep-alive


Kong is now aware of your Service and ready to proxy requests.

Back to TOC

3. Forward your requests through Kong

Issue the following cURL request to verify that Kong is properly forwarding requests to your Service. Note that by default Kong handles proxy requests on port :8000:

$ curl -i -X GET \
  --url http://localhost:8000/ \
  --header 'Host:'

A successful response means Kong is now forwarding requests made to http://localhost:8000 to the 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: <given host>

Back to TOC

Next Steps

Now that you’ve added your Service to Kong, let’s learn how to enable plugins.

Go to Enabling Plugins ›