Simple Gateway API Example
This example demonstrates a basic setup of the Gateway API with a PostgreSQL database, showcasing how to create a simple REST API service.
Components
- Gateway API: REST API service with team and persona endpoints
- PostgreSQL: Database storing team and persona data
Prerequisites
- Docker
- Docker Compose
Getting Started
-
Start all services:
Terminal window docker-compose up -d -
Services will be available at:
- Gateway API: http://localhost:8182
- PostgreSQL: localhost:5432
# Verify the functionality by runningcurl -X 'GET' 'http://localhost:8182/raw/query?query=SELECT%201'Swagger will be avilable in http://localhost:8182/swagger/
API Endpoints
Teams Endpoints
- List Teams
GET /teamsQuery parameters:
limit(optional, default: 5): Number of resultsoffset(optional, default: 0): Pagination offset
- Get Team by ID
GET /teams/{id}- Get Total Teams Count
GET /teams/total_countPersonas Endpoints
- List Personas
GET /personasQuery parameters:
limit(optional, default: 5): Number of resultsoffset(optional, default: 0): Pagination offset
- Get Persona by ID
GET /personas/{id}- Get Total Personas Count
GET /personas/total_countDatabase Schema
The database contains two main tables:
Teams Table
id: Serial Primary Keyteam_name: VARCHAR(50)motto: VARCHAR(100)
Personas Table
id: Serial Primary Keyname: VARCHAR(50)strength_level: INTspecial_move: VARCHAR(100)favorite_drink: VARCHAR(50)battle_cry: VARCHAR(100)team_id: INT (Foreign Key to Teams Table)
Configuration Files
docker-compose.yml: Service orchestrationconfig.yaml: Gateway API configuration with endpoint definitionsconnection.yaml: Database connection settingsinit.sql: Database initialization script with sample data
Data Loading
Sample data for teams and personas is automatically loaded during initialization through the init.sql script.