A production-ready PHP API built with Slim Framework, featuring JWT authentication, dependency injection, logging, and Swagger documentation.
- Slim Framework 4 - Modern PHP micro-framework
- JWT Authentication - Secure token-based authentication with JWKS support
- Dependency Injection - PHP-DI container for clean architecture
- Logging - Monolog for comprehensive logging
- Swagger Documentation - OpenAPI 3.0 specification with interactive UI
- CORS Support - Configurable cross-origin resource sharing
- Environment Configuration - dotenv for environment variables
- PSR-4 Autoloading - Modern PHP namespace structure
- Install dependencies:
composer install
- Copy environment file:
cp example.env cfg.env
-
Configure your environment variables in
cfg.env
-
Create logs directory:
mkdir logs
- Start development server:
php -S localhost:8000 router.php
GET /health
- Health check endpointGET /api/v1/beers/random
- Get random beerGET /api/v1/beers/{id}
- Get beer by idGET /docs
- Swagger UI documentationGET /docs/openapi.json
- OpenAPI specification
The API uses JWT tokens for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
For beer endpoints, the token must contain an 'admin' role in the realm_access.roles
claim.
APP_ENV
- Application environment (development/production)APP_DEBUG
- Enable debug mode (true/false)APP_NAME
- Application name for loggingJWKS_URI
- JWT Key Set URI for token validationJWT_ALGORITHM
- JWT algorithm (default: RS256)LOG_LEVEL
- Logging level (debug/info/warning/error)LOG_PATH
- Path to log fileCORS_ALLOWED_ORIGINS
- Comma-separated list of allowed CORS origins or *
The application follows a clean architecture pattern:
- Controllers - Handle HTTP requests and responses
- Services - Business logic and external API calls
- Repositories - Business logic and external API calls
- Middleware - Cross-cutting concerns (CORS, Authentication)
- Config - Application bootstrapping and dependency injection
Interactive API documentation is available at /docs
when the server is running.
MIT