Download the PHP package schentrup-software/php-api without Composer
On this page you can find all versions of the php package schentrup-software/php-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download schentrup-software/php-api
More information about schentrup-software/php-api
Files in schentrup-software/php-api
Package php-api
Short Description A basic api framework for PHP. It uses classes for request and responses to make a self documenting API.
License MIT
Informations about the package php-api
PHP API
A basic api framework for PHP. It uses classes for request and responses to make a self documenting API. It uses pmjones/AutoRoute for routing and sapienphp/sapien for request and response objects.
Features
- Convention-Based Routing: Automatically maps URLs to controller classes based on directory structure and naming conventions
- Strongly Typed Requests/Responses: Type-safe request and response objects with automatic parameter parsing
- Auto-Generated Swagger Documentation: API documentation automatically generated from your code and PHP attributes
- Middleware Support: Add request/response middleware for cross-cutting concerns like authentication and logging
- Content Negotiation: Support for different content types (JSON, Form data, etc.)
- Input Validation: Automatic validation and type conversion of request parameters
- Path Variables: Support for dynamic path segments in routes
- Error Handling: Customizable error responses for various error conditions
- Attribute-Based Metadata: Use PHP 8 attributes for documentation and parameter configuration
- Parameter Sources: Get input from different sources (query parameters, JSON body, cookies, headers)
Installation
Basic Usage
-
Create a Router
- Create a Simple Controller
Request Parameters
PHP-API supports multiple parameter sources:
Query Parameters
JSON Body Parameters
or
Header Parameters
Cookie Parameters
Middleware
Request Middleware
Response Middleware
Adding Middleware
Error Handling
Swagger Documentation
PHP-API automatically generates Swagger/OpenAPI documentation from your code. Access the documentation at:
- /swagger - Swagger UI interface
- /swagger/json - Raw JSON OpenAPI definition
Use attributes to enhance the documentation:
Path Variables
Path variables are automatically mapped to method parameters:
More info on this can be found in the auto-router documentation: pmjones/auto-route.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.