A robust and feature-rich API template built with PHP Slim Framework, providing ready-to-use implementations for weather data, QR code generation, and more.
- 🚀 Built with Slim 4 Framework
- 🌤️ Weather API Integration with OpenWeatherMap
- 📱 QR Code Generation API
- 🔐 Proper Error Handling
- 📁 Well-organized Project Structure
- 🛠️ Easy to Extend and Customize
api-project/
├── composer.json
├── .htaccess
├── public/
│ ├── index.php
│ └── .htaccess
├── src/
│ ├── Config/
│ │ └── settings.php
│ ├── Controllers/
│ │ ├── HelloController.php
│ │ ├── WeatherController.php
│ │ └── QRCodeController.php
│ ├── Routes/
│ │ └── api.php
│ └── bootstrap.php
└── vendor/
- PHP >= 7.4
- Composer
- Apache/Nginx Web Server
- GD extension (for QR code generation)
- Clone the repository:
git clone https://github.com/1dev-hridoy/SlimApiTemplate.git- Install dependencies:
composer install-
Configure your web server to point to the
publicdirectory -
Copy
.htaccessfiles to their respective locations
GET /api/hello# Get current weather
GET /api/weather?city={cityName}
# Get weather forecast
GET /api/weather/forecast?city={cityName}Parameters:
city: Name of the city (required)
# Generate QR code as image
GET /api/qr/generate?text={text}&size={size}&label={label}
# Generate QR code as base64
GET /api/qr/base64?text={text}Parameters:
text: Content to encode in QR code (required)size: Size of QR code in pixels (optional, default: 300)label: Text label below QR code (optional)
fetch('http://your-domain/api/weather?city=London')
.then(response => response.json())
.then(data => console.log(data));<!-- Display QR code directly -->
<img src="http://your-domain/api/qr/generate?text=Hello World" alt="QR Code">
<!-- With custom size -->
<img src="http://your-domain/api/qr/generate?text=Hello World&size=200" alt="QR Code">Update the OpenWeather API key in src/Controllers/WeatherController.php:
private $apiKey = 'your-api-key';- Fork the repository
- Create a new branch (
git checkout -b feature/improvement) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/improvement) - Create a Pull Request
- Hridoy - GitHub Profile
This project is licensed under the MIT License - see the LICENSE file for details
If you find this template helpful, please consider giving it a ⭐️ on GitHub!
2025-03-29 17:26:17 UTC by @hridoy09bg