PHPackages                             schentrup-software/php-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. schentrup-software/php-api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

schentrup-software/php-api
==========================

A basic api framework for PHP. It uses classes for request and responses to make a self documenting API.

v0.1.0(1y ago)12MITPHPPHP &gt;=8.1CI passing

Since Apr 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Schentrup-Software/PHP-API)[ Packagist](https://packagist.org/packages/schentrup-software/php-api)[ GitHub Sponsors](https://github.com/joeySchentrup)[ RSS](/packages/schentrup-software-php-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

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](https://github.com/pmjones/AutoRoute) for routing and [sapienphp/sapien](https://github.com/sapienphp/sapien) for request and response objects.

[![PHP Analysis And Tests](https://github.com/Schentrup-Software/PHP-API/actions/workflows/php.yml/badge.svg)](https://github.com/Schentrup-Software/PHP-API/actions/workflows/php.yml)

Features
--------

[](#features)

- **Convention-Based Routing**: Automatically maps [URLs to controller classes](https://github.com/pmjones/AutoRoute?tab=readme-ov-file#how-it-works) 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](https://github.com/pmjones/AutoRoute?tab=readme-ov-file#dynamic-parameters) 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
------------

[](#installation)

```
composer require schentrup-software/php-api

```

Basic Usage
-----------

[](#basic-usage)

1. Create a Router

```
