Member-only story

How to register FastAPI service with Kong API Gateway

Introduction

Abhishek koserwal
5 min readDec 7, 2024

API gateways serve as the gatekeepers of microservices, providing critical capabilities such as routing, authentication, rate-limiting, and monitoring. In this blog, we’ll walk through setting up a FastAPI REST API behind a Kong API Gateway using Docker Compose. This setup allows you to manage and secure your API endpoints efficient

Prerequisites

To follow this tutorial, you’ll need:

  • Podman/Docker and Docker Compose installed
  • FastAPI (A modern, fast web framework for Python)
  • Uvicorn (ASGI server for FastAPI)

Code Repository

git clone https://github.com/akoserwal/fastapi-patterns
cd fastapi-kong/

Step 1: Setting Up the FastAPI Application

We’ll start by creating a basic FastAPI application.

Create the virtual env

uv venv

Install the Fast API and Uvicorn dependencies

pip install "fastapi[all]" uvicorn

Create a simple main.py file which exposes two endpoints /api/helloand /api/hello/{name}

from fastapi import FastAPI

app = FastAPI()


@app.get("/api/hello")
async def root():
return {"message": "Hello World"}


@app.get("/api/hello/{name}")
async def say_hello(name: str)…

--

--

Abhishek koserwal
Abhishek koserwal

Written by Abhishek koserwal

#redhatter #opensource #developer #kubernetes #keycloak #golang #openshift #quarkus #spring

Responses (1)