API Management
API Management Overview
API Management - the art of funnelling traffic from an API client through to the background service and taking care of things like authentication, rate-limiting, logging, auditing etc.
There are lots of solutions out there - both FOSS and commercial.
Google Solutions
Google have three solutions that they discuss on their cloud platform docs site (mirror):
- ApiGee - looks like the super expensive enterprisey option not really an option for new products
- API Gateway - seems to just provide a gateway that allows the internet to
- Cloud Gateway - seems to be a really customisable/complex version of API Gateway
Seems like API Gateway might be useful if you are running cloud functions. Apigee is SOO SOO expensive - it starts at $700/month.
FOSS Solutions
Started exploring from this list (mirror) :
- Looked at API Umbrella - it seems like they haven't; made any releases since 2019 and I'm not sure how maintained it is so staying away for now.
- Started playing with Kong Gateway - it is lightweight, stores data in Postgres and looks easy to use with docker-compose.
Kong Gateway
Kong Gateway is an open core project that offers many of the traditional API Management features.
Minimal Docker Compose for Kong
version: "3.0"
services:
kong:
env_file: .env
image: kong/kong-gateway:3.0.1.0
environment:
- KONG_DATABASE=postgres
- KONG_PG_HOST=db
- KONG_PG_DATABASE=kong
- KONG_PG_USER=postgres
- KONG_PG_PASSWORD=${POSTGRES_PASSWORD}
- KONG_ADMIN_LISTEN=0.0.0.0:8001
- KONG_ADMIN_GUI_URL=http://localhost:8002
ports:
- 8000:8000
- 8443:8443
- 8001:8001
- 8444:8444
- 8002:8002
- 8445:8445
- 8003:8003
- 8004:8004
db:
env_file: .env
image: postgres
restart: always
volumes:
- ./postgres:/var/lib/postgresql/data
ports:
- 5432:5432
adminer:
env_file: .env
image: adminer
restart: always
ports:
- 8080:8080
And accompanying .env
file:
POSTGRES_PASSWORD=example
KONG_PASSWORD="supersecret123"
Docker Compose Installation
The official documentation for the project provides a walkthrough for docker installation here
Seed the Database
docker-compose run kong kong migrations bootstrap
Starting Kong
docker-compose up -d kong
Kong Config and Environment Variables
Kong normally reads a config file called kong.conf
- an overview of valid configuration settings/directives can be found here
The docker image can read these variables from the environment. Simply copy the name of the thing, upercase it and prefix with KONG_
e.g. prefix
becomes KONG_PREFIX
.