PHPackages                             webfiori/http - 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. webfiori/http

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

webfiori/http
=============

Basic library that can help in creating RESTful APIs using PHP.

6.0.3(1mo ago)748.1k↑3341.7%[1 issues](https://github.com/WebFiori/http/issues)3MITPHPPHP &gt;=8.1CI passing

Since Apr 23Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/WebFiori/http)[ Packagist](https://packagist.org/packages/webfiori/http)[ RSS](/packages/webfiori-http/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (9)Versions (104)Used By (3)

WebFiori HTTP
=============

[](#webfiori-http)

A powerful and flexible PHP library for creating RESTful web APIs with built-in input filtering, data validation, and comprehensive HTTP utilities. The library provides a clean, object-oriented approach to building web services with automatic parameter validation, authentication support, and JSON response handling.

 [ ![](https://github.com/WebFiori/http/actions/workflows/php85.yaml/badge.svg?branch=main) ](https://github.com/WebFiori/http/actions) [ ![](https://camo.githubusercontent.com/3b07032b8cb2a34136b30063ea03bbd2a806b24bfb6a3242f4c73f957af1f348/68747470733a2f2f636f6465636f762e696f2f67682f57656246696f72692f687474702f6272616e63682f6d61696e2f67726170682f62616467652e737667) ](https://codecov.io/gh/WebFiori/http) [ ![](https://camo.githubusercontent.com/e627892dc5ac438c14890d080a8be22226732d742ef439e1bd7f3daaf5a3953a/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d57656246696f72695f68747470266d65747269633d616c6572745f737461747573) ](https://sonarcloud.io/dashboard?id=WebFiori_http) [ ![](https://camo.githubusercontent.com/862e84d7c31b3de337a0bcc47e7ba8ef6a82d86f00b6cc9c455b8d8e469ea0b2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f57656246696f72692f687474702e7376673f6c6162656c3d6c6174657374) ](https://github.com/WebFiori/http/releases) [ ![](https://camo.githubusercontent.com/fa3b12ecffa5b3f673457d3762f8076fde70b85812639b7305fb88b9ad9a2c4b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656266696f72692f687474703f636f6c6f723d6c696768742d677265656e) ](https://packagist.org/packages/webfiori/http)

Table of Contents
-----------------

[](#table-of-contents)

- [Motivation](#motivation)
- [Supported PHP Versions](#supported-php-versions)
- [Key Features](#key-features)
- [Installation](#installation)
- [Quick Start](#quick-start)

    - [Modern Approach with Attributes](#modern-approach-with-attributes)
    - [Traditional Approach](#traditional-approach)
- [Core Concepts](#core-concepts)
- [Creating Web Services](#creating-web-services)

    - [Using Attributes (Recommended)](#using-attributes-recommended)
    - [Traditional Class-Based Approach](#traditional-class-based-approach)
- [Parameter Management](#parameter-management)
- [Dynamic Status Codes with ResponseEntity](#dynamic-status-codes-with-responseentity)
- [Testing](#testing)
- [Examples](#examples)

Motivation
----------

[](#motivation)

With well-established PHP HTTP libraries available, you might wonder why this one exists.

**Validation is not optional.** In most frameworks, input validation is a separate step you wire up after defining your routes. Here, you cannot define an endpoint without declaring exactly what data it accepts, its type, and how it should be validated. The API contract is the code.

**Minimal dependencies.** The library has a single runtime dependency (`webfiori/jsonx`). No PSR-7 stack, no framework coupling, no transitive dependency tree. What you install is what you get.

**One service, one unit.** Each endpoint is a self-contained object with its own parameters, authorization logic, and processing — independently testable and self-documenting. Built-in OpenAPI spec generation is a natural result of this design.

**Full control.** Request parsing, header management, content negotiation, and response handling are all implemented internally. No hidden layers, no framework tax.

Supported PHP Versions
----------------------

[](#supported-php-versions)

Build Status[![](https://github.com/WebFiori/http/actions/workflows/php81.yaml/badge.svg?branch=main)](https://github.com/WebFiori/http/actions/workflows/php81.yaml)[![](https://github.com/WebFiori/http/actions/workflows/php82.yaml/badge.svg?branch=main)](https://github.com/WebFiori/http/actions/workflows/php82.yaml)[![](https://github.com/WebFiori/http/actions/workflows/php83.yaml/badge.svg?branch=main)](https://github.com/WebFiori/http/actions/workflows/php83.yaml)[![](https://github.com/WebFiori/http/actions/workflows/php84.yaml/badge.svg?branch=main)](https://github.com/WebFiori/http/actions/workflows/php84.yaml)[![](https://github.com/WebFiori/http/actions/workflows/php85.yaml/badge.svg?branch=main)](https://github.com/WebFiori/http/actions/workflows/php85.yaml)Key Features
------------

[](#key-features)

- **RESTful API Development**: Full support for creating REST services with JSON request/response handling
- **Automatic Input Validation**: Built-in parameter validation with support for multiple data types
- **Custom Filtering**: Ability to create user-defined input filters and validation rules
- **Authentication Support**: Built-in support for various authentication schemes (Basic, Bearer, etc.)
- **HTTP Method Support**: Support for all standard HTTP methods (GET, POST, PUT, DELETE, etc.)
- **Content Type Handling**: Support for `application/json`, `application/x-www-form-urlencoded`, and `multipart/form-data`
- **Object Mapping**: Automatic mapping of request parameters to PHP objects
- **Comprehensive Testing**: Built-in testing utilities with `ServiceTestCase` class
- **Error Handling**: Structured error responses with appropriate HTTP status codes
- **Stream Support**: Custom input/output stream handling for advanced use cases

Installation
------------

[](#installation)

### Using Composer (Recommended)

[](#using-composer-recommended)

```
composer require webfiori/http
```

### Manual Installation

[](#manual-installation)

Download the latest release from [GitHub Releases](https://github.com/WebFiori/http/releases) and include the autoloader:

```
require_once 'path/to/webfiori-http/vendor/autoload.php';
```

Quick Start
-----------

[](#quick-start)

### Modern Approach with Attributes (Recommended)

[](#modern-approach-with-attributes-recommended)

PHP 8+ attributes provide a clean, declarative way to define web services:

```
