Thomas Landis

Swapping stories with strangers at the bar. Shooting the breeze on the back porch. Chatting up the retailers at the Watchung Square Mall. Tom had a knack for making friends everywhere he went. The…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Configuring Services in Kong API

This is the third story of the https://medium.com/kong-api-devops-lab/ publication. You can refer to https://medium.com/kong-api-devops-lab/kongapi-installation-23814f135394 for the second story.

In this story, you’ll learn how to expose your Services using Routes. 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.

Service and Route objects let you expose your services to clients with Kong Gateway. When configuring access to your API, you’ll start by specifying a Service. In Kong Gateway, a Service is an entity representing an external upstream API or microservice — for example, a data transformation microservice, a billing API, and so on.

The main attribute of a Service is its URL, where the service listens for requests. You can specify the URL with a single string, or by specifying its protocol, host, port, and path individually.

Before you can start making requests against the Service, you will need to add a Route to it. Routes determine how (and if) requests are sent to their Services after they reach Kong Gateway. A single Service can have many Routes.

After configuring the Service and the Route, you’ll be able to start making requests through Kong Gateway.

This diagram illustrates the flow of requests and responses being routed through the Service to the backend API.

Let’s see what services the Kong already has currently by invoking the below curl command.

Well, there is no service currently configured.

Let’s create, by running a POST command using curl.

Well, you have just created one service, called backend-api service.

For sake of understanding multiple services in Kong, let’s create another one.

You have just created a mock service.

Now, verify that the services are created, using the same curl command we invoked earlier.

For the Service to be accessible through the Kong Gateway, you need to add a Route to it.

There are two types of routes in Kong API, hostname based and pathname based.

Let’s create hostname based route to the backend-api.

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

Let’s test this route

Let’s also add new route by path to the backend-api

and test it

In case you want to delete a service and route (which you should not delete the service and routes we just created, because we are going to use them in next stories), you will need to delete all routes under that particular service, and then delete the service.

To delete a route

To delete a service

Check out my next story https://medium.com/kong-api-devops-lab/enable-key-auth-plugin-71e24cfb6325

Add a comment

Related posts:

Naughty Nurse Charged With Stealing From A Coronavirus Patient

As the coronavirus pandemic begins to wind down, frontline workers are being rightfully praised. This includes the doctors, nurses, and other hospital personnel who put their lives on the line to…

How can SEO help my startup or small business?

As a startup or small business owner, you may wonder how you can improve your online presence and attract more potential customers. One strategy that can help you achieve this goal is search engine…