A simple API example demonstrating the Okapi Go Web Framework
2.6K
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.
This example demonstrates:
# 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 run --rm --name okapi-example \
-p 8080:8080 \
-e JWT_SECRET=your-secret-key \
jkaninda/okapi-example
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
Configure the application using environment variables:
| Variable | Description | Default |
|---|---|---|
JWT_SECRET | JWT token signing secret | default-secret-key |
| 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 |
| Variable | Description | Default |
|---|---|---|
PORT | HTTP server port | 8080 |
TLS_PORT | HTTPS server port | 8443 |
ENABLE_DOCS | Enable Swagger UI documentation | true |
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
Once running, visit:
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

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

After exploring this example:
routes/ directory to fit your needsMITā - Feel free to use, modify, and distribute this example for any purpose.
Content type
Image
Digest
sha256:57dd4dbedā¦
Size
14.7 MB
Last updated
8 months ago
docker pull jkaninda/okapi-example