Skip to content

jkaninda/okapi-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Okapi Example

A comprehensive example application showcasing the Go Okapi API Framework's core features and best practices.

Okapi is a modern, minimalist HTTP web framework for Go, inspired by FastAPI's elegance. Built for simplicity, performance, and developer happiness, it enables you to build fast, scalable, and well-documented APIs with minimal boilerplate.

πŸ”— Links

✨ What's Included

This example demonstrates:

  • Core Framework Usage - Basic Okapi implementation patterns
  • Middleware Integration - Custom and built-in middleware examples
  • Route Organization - Structured route definitions and grouping
  • Real-time Communication - Server-Sent Events (SSE) and WebSocket implementations
  • Template Rendering - HTML template integration
  • API Documentation - Automatic Swagger/OpenAPI generation
  • Production-Ready Structure - Clean, maintainable code organization

πŸš€ Quick Start

Prerequisites

  • Go 1.21 or higher
  • Git

Local Development

# Clone the repository
git clone https://github.com/jkaninda/okapi-example
cd okapi-example

# Install dependencies
go mod tidy

# Run the application
go run .

The server will start at http://localhost:8080

Docker Deployment

docker run --rm --name okapi-example \
  -p 8080:8080 \
  -e JWT_SIGNING_SECRET=your-secret-key \
  jkaninda/okapi-example

With HTTPS/TLS:

docker run --rm --name okapi-example \
  -p 8080:8080 \
  -p 8443:8443 \
  -e JWT_SECRET=your-secret-key \
  -e TLS_CERT_PATH=/certs/server.crt \
  -e TLS_KEY_PATH=/certs/server.key \
  -v /path/to/certs:/certs:ro \
  jkaninda/okapi-example

βš™οΈ Configuration

Configure the application using environment variables:

Security

Variable Description Default
JWT_SECRET JWT token signing secret default-secret-key

TLS/HTTPS

Variable Description Default
TLS_CERT_PATH Path to TLS certificate file (empty - TLS disabled)
TLS_KEY_PATH Path to TLS private key file (empty - TLS disabled)
TLS_CA_PATH Path to CA certificate for mutual TLS (empty - no client auth)
TLS_REQUIRE_AUTH Require client certificate authentication false

Server

Variable Description Default
PORT HTTP server port 8080
TLS_PORT HTTPS server port 8443
ENABLE_DOCS Enable Swagger UI documentation true

Example Configuration

Create a .env file in the project root:

# Security
JWT_SECRET=your-secret-key

# TLS Configuration (optional)
#TLS_CERT_PATH=/path/to/cert.pem
#TLS_KEY_PATH=/path/to/key.pem
#TLS_CA_PATH=/path/to/ca.pem
#TLS_REQUIRE_AUTH=false

# Server Configuration
ENABLE_DOCS=true
PORT=8080
TLS_PORT=8443

πŸ“š Explore the Example

Once running, visit:

πŸ“ Project Structure

okapi-example/
β”œβ”€β”€ main.go              # Application entry point and server setup
β”œβ”€β”€ routes/              # API route definitions and handlers
β”œβ”€β”€ middlewares/         # Custom middleware implementations
β”œβ”€β”€ services/            # Business logic and service layer
β”œβ”€β”€ models/              # Data models and structures
β”œβ”€β”€ session/             # Session management utilities
└── README.md

Architecture Highlights

  • Layered Design: Clear separation between routes, services, and models
  • Middleware Pipeline: Reusable middleware for authentication, logging, and CORS
  • Service Layer: Business logic and service layer
  • Session Management: Built-in session handling utilities

πŸ“Έ Screenshots

Home Page

Home Page - Okapi Example

Interactive API Documentation

Okapi automatically generates comprehensive Swagger UI documentation for all your routes, making API exploration and testing effortless.

Swagger UI - Auto-generated API documentation

🎯 Next Steps

After exploring this example:

  1. Read the Documentation: Visit the Okapi docs for detailed guides
  2. Customize Routes: Modify the routes in the routes/ directory to fit your needs
  3. Add Features: Extend the example with database integration, authentication, etc.
  4. Deploy: Use the included Docker setup for production deployments

πŸ“„ License

MIT - Feel free to use, modify, and distribute this example for any purpose.

Packages

 
 
 

Contributors