Production-ready starter template for API integrations in PHP: clean
structure, .env config, cURL HTTP client, logging, error handling, and
demo endpoints.
Built for real-world use cases: connecting external APIs, handling retries/errors, and keeping a clear audit trail (logs).
- ✅ Simple, clean project structure (
public/,src/,examples/) - ✅
.envconfiguration via.env.example - ✅ cURL-based HTTP client with consistent response shape
- ✅ File logging (
storage/logs/app.log) in JSON lines - ✅ Demo endpoints:
GET /healthPOST /proxy→ forwards payload to an external API (default: httpbin)
flowchart LR
A["Client / Postman"] -->|HTTP| B["public/index.php Router"]
B --> C["Config - .env"]
B --> D["Logger - JSON logs"]
B --> E["HttpClient - cURL"]
E --> F["External API"]
D --> G["storage/logs/app.log"]
- PHP 8.0+ (recommended)
cp .env.example .envEdit .env if needed:
API_BASE_URLAPI_KEYTIMEOUTLOG_PATH
php -S 127.0.0.1:8000 -t publiccurl http://127.0.0.1:8000/healthExpected response:
{
"ok": true,
"service": "api-integration-starter-php",
"ts": "2026-02-15T00:00:00Z"
}curl -X POST http://127.0.0.1:8000/proxy \
-H "Content-Type: application/json" \
-d '{"demo": true, "message": "Hello"}'This will forward your JSON payload to:
${API_BASE_URL}/post
(default: https://httpbin.org/post)
api-integration-starter-php/
├─ public/
│ └─ index.php
├─ src/
│ ├─ Config.php
│ ├─ Logger.php
│ └─ Http/
│ └─ HttpClient.php
├─ examples/
│ └─ request-example.php
├─ .env.example
└─ README.md
Logs are written as JSON lines to:
storage/logs/app.log (default)
Example log entry:
{
"ts": "2026-02-15T00:00:00Z",
"level": "INFO",
"message": "HTTP request",
"context": {
"method": "POST",
"url": "https://httpbin.org/post",
"has_body": true
}
}This repo is intentionally safe by design:
- ✅ No real keys stored in code
- ✅
.envis ignored (keep secrets local) - ✅ Demo flows use placeholder endpoints
- ✅ Clear separation between configuration and runtime logic
- Add retry with exponential backoff (idempotent-safe calls)
- Add correlation ID for request tracing
- Add webhook signature validation helper
- Add simple response caching example
Rober Lopez
Backend & API Integration Specialist · Payments · Automation ·
UX/UI-minded Engineer
- 🌐 Website: https://roberlopez.com
- 💻 GitHub: https://github.com/kirito18
- 🔗 LinkedIn: https://www.linkedin.com/in/web-rober-lopez/