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.

5.0.5(2w ago)645.8k—0%2MITPHPPHP &gt;=8.1CI passing

Since Apr 23Pushed 2w ago1 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (88)Used By (2)

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)

- [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)
- [Testing](#testing)
- [Examples](#examples)

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 `APITestCase` 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:

```
