luk-z / api-proxy-php
API Proxy written in PHP using Lumen framework
Requires
- php: ^7.3|^8.0
- laravel/lumen-framework: ^8.0
- luk-z/php-api-token-auth: ^0.1.18
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.89
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^4.0
README
api-proxy-php
A PHP API proxy (headless) project built using the Lumen framework.
This is a lightweight API proxy built with Lumen (Laravel micro-framework). It provides a simple REST API structure without database or view management.
Usage in applications
- Install as dependency
composer require luk-z/api-proxy-php
- Add custom includes To add custom Controllers and Routes just define these constants:
- Copy the environment file:
cp .env.example .env
Required define
In order to work the following php define should be defined:
- APP_TABLE_APPS
These php defined are optional
APP_ADD_DEFAULT_ROUTES: add default hello world and test routesAPP_CUSTOM_INCLUDES_PATHAPP_CUSTOM_ROUTES_PATH
Requirements
- PHP 7.3 or higher
- Composer
Development
Setup local machine
To install dependencies php 7.3+ and composer are needed. Instead installing them in the local machine use a dockerized composer (requires Docker Desktop).
Create php and composer aliases following this guide.
- Clone the repository:
git clone https://github.com/lukzed/api-proxy-php.git project_name && rm -rf ./project_name/.git cd project_name
-
Install suggested vscode extensions
-
Copy the
php-cs-fixer-wrapper.shfile:
cp php-cs-fixer-wrapper.sh.example php-cs-fixer-wrapper.sh
change WORKSPACE_ROOT="<absolute path to your workspace>" inserting the application absolute path (use pwd command to obtain absolute path)
- Install dependencies:
composer install
Running the Application
Start the development server:
php -S localhost:8000 -t public
The application will be available at http://localhost:8000.
Development Tools
Code Quality and Formatting
This project includes PHP linting and formatting tools that work seamlessly with Visual Studio Code.
Tools Included
- PHP_CodeSniffer (PHPCS): Linter for detecting coding standard violations (PSR-12)
- PHP CS Fixer: Automatic code formatter
- PHPUnit: Testing framework for unit and integration tests
Visual Studio Code Setup
-
Install the recommended extensions when prompted, or manually install:
- PHP CS Fixer (
junstyle.php-cs-fixer) - PHP_CodeSniffer (
ikappas.phpcs) - PHP Intelephense (
bmewburn.vscode-intelephense-client)
- PHP CS Fixer (
-
The workspace settings (
.vscode/settings.json) are pre-configured to:- Enable format on save
- Run PHP CS Fixer automatically
- Show PHPCS violations in real-time
Command Line Usage
Check for coding standard violations:
composer lint
Automatically fix coding standard violations:
composer lint:fix
Format code using PHP CS Fixer:
composer format
Check what PHP CS Fixer would change (dry run):
composer format:check
Configuration Files
phpcs.xml- PHP_CodeSniffer configuration (PSR-12 standard).php-cs-fixer.php- PHP CS Fixer configurationphpunit.xml- PHPUnit configuration.vscode/settings.json- VS Code workspace settings.vscode/extensions.json- Recommended VS Code extensions
Testing
This project uses PHPUnit for testing.
Run all tests:
composer test
Run tests with coverage:
./vendor/bin/phpunit --coverage-html coverage
Tests are located in the tests/ directory and follow the PSR-12 coding standard.
API Endpoints
Root Endpoint
GET /
Returns the Lumen version information.
Hello World Endpoint
GET /hello
Returns a simple JSON response:
{
"message": "Hello World!"
}
Project Structure
.
├── app/
│ ├── Console/ # Console commands
│ ├── Exceptions/ # Exception handlers
│ └── Http/
│ └── Controllers/ # API controllers
├── bootstrap/ # Framework bootstrap
├── public/ # Public web root
├── routes/ # Route definitions
└── storage/ # Logs and cache
License
This project is open-sourced software licensed under the MIT license.