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

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

fperdomo/http
=============

HTTP Component

2.0.0(3mo ago)0796↓33.3%MITPHPPHP &gt;=8.3CI passing

Since Mar 5Pushed 3mo agoCompare

[ Source](https://github.com/masterfermin02/http)[ Packagist](https://packagist.org/packages/fperdomo/http)[ RSS](/packages/fperdomo-http/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (7)Versions (5)Used By (0)

Http Component
--------------

[](#http-component)

GitHub repository:

[![Latest Stable Version](https://camo.githubusercontent.com/92cf89aff36e53bbca9c8abe3fbd9af2a15d5771f5d379ec70812fc02f580581/68747470733a2f2f706f7365722e707567782e6f72672f66706572646f6d6f2f687474702f762f737461626c652e737667)](https://packagist.org/packages/fperdomo/http) [![Total Downloads](https://camo.githubusercontent.com/a3c824fb59ae88b71aa60ad348803712c3dce7824b8ede9a7b321e0a5e86b57e/68747470733a2f2f706f7365722e707567782e6f72672f66706572646f6d6f2f687474702f646f776e6c6f6164732e737667)](https://packagist.org/packages/fperdomo/http) [![License](https://camo.githubusercontent.com/8d1eb1ba0bb4c7650faf464a2442abc68a333dec4b5b6482ba45898c21e2493e/68747470733a2f2f706f7365722e707567782e6f72672f66706572646f6d6f2f687474702f6c6963656e73652e737667)](https://packagist.org/packages/fperdomo/http)

A modern, lightweight HTTP component for PHP 8.3+ with **full PSR-7, PSR-17, and PSR-15 interoperability**.

Features
--------

[](#features)

**Simple &amp; Intuitive API** - Clean object-oriented wrappers around PHP superglobals
**PSR-7 Compatible** - HTTP message interfaces for request/response handling
**PSR-17 Factory Support** - Standard factory methods for creating HTTP objects
**PSR-15 Middleware** - Full middleware and request handler support
**Modern PHP** - Built for PHP 8.3+ with typed properties and readonly classes
**Framework Agnostic** - Works with any PHP framework or standalone

Why This Package?
-----------------

[](#why-this-package)

This is a maintained fork that brings modern PHP 8.3+ support and PSR interoperability to a proven HTTP component. The original package hasn't been updated since 2016, but this version is actively maintained with:

- PHP 8.3+ support with modern type hints
- PSR-7, PSR-17, and PSR-15 adapters for ecosystem compatibility
- Continuous integration and automated testing
- Regular updates and community support

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

[](#installation)

```
composer require fperdomo/http
```

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

[](#quick-start)

### Traditional Approach (Simple &amp; Direct)

[](#traditional-approach-simple--direct)

```
use Http\HttpRequest;
use Http\HttpResponse;

$request = new HttpRequest($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, file_get_contents('php://input'));
$response = new HttpResponse;

$name = $request->getParameter('name', 'Guest');
$response->setContent("Hello, {$name}!");
$response->addHeader('Content-Type', 'text/html');

foreach ($response->getHeaders() as $header) {
    header($header, false);
}
echo $response->getContent();
```

### PSR-7 Approach (Framework Interoperability)

[](#psr-7-approach-framework-interoperability)

```
use Http\Psr\Psr7RequestFactory;
use Http\Psr\Psr7ResponseFactory;

// Create PSR-7 compliant objects
$factory = new Psr7RequestFactory();
$request = $factory->createServerRequestFromGlobals();

$responseFactory = new Psr7ResponseFactory();
$response = $responseFactory->createResponse(200)
    ->withHeader('Content-Type', 'application/json');

$response->getBody()->write(json_encode(['status' => 'success']));
```

### PSR-15 Middleware (Modern Architecture)

[](#psr-15-middleware-modern-architecture)

```
use Http\Psr\Psr15Handler;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class AuthMiddleware implements MiddlewareInterface {
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
        // Authentication logic here
        return $handler->handle($request);
    }
}

$handler = new Psr15Handler();
$handler->addMiddleware(new AuthMiddleware());
$response = $handler->handle($request);
```

PSR Interoperability
--------------------

[](#psr-interoperability)

### PSR-7: HTTP Message Interfaces

[](#psr-7-http-message-interfaces)

Use the provided adapters to convert between native objects and PSR-7 interfaces:

```
use Http\HttpRequest;
use Http\HttpResponse;

// Convert native request to PSR-7
$nativeRequest = new HttpRequest($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, file_get_contents('php://input'));
$psr7Request = $nativeRequest->toPsrServerRequest();

// Convert native response to PSR-7
$nativeResponse = new HttpResponse();
$psr7Response = $nativeResponse->toPsrResponse();

// Convert PSR-7 response back to native
$httpResponse = HttpResponse::fromPsrResponse($psr7Response);
```

**📚 [Complete PSR Interoperability Guide](docs/PSR-INTEROPERABILITY.md)** | **🚀 [Quick Start](docs/PSR-QUICKSTART.md)**

### PSR-17: HTTP Factories

[](#psr-17-http-factories)

Create HTTP objects using standard factory interfaces:

```
use Http\Psr\Psr17Factory;

$factory = new Psr17Factory();

// Request factories
$request = $factory->createRequest('GET', 'https://example.com');
$serverRequest = $factory->createServerRequestFromGlobals(); // From superglobals

// Response factory
$response = $factory->createResponse(200, 'OK');

// Message component factories
$stream = $factory->createStream('Hello World');
$uri = $factory->createUri('https://example.com/path');
```

### PSR-15: Middleware &amp; Request Handlers

[](#psr-15-middleware--request-handlers)

Build middleware pipelines compatible with any PSR-15 framework:

```
use Http\Psr\MiddlewarePipeline;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

$pipeline = new MiddlewarePipeline();

// Add middleware
$pipeline->pipe(new AuthenticationMiddleware());
$pipeline->pipe(new LoggingMiddleware());
$pipeline->pipe($finalHandler);

// Process request through pipeline
$response = $pipeline->handle($serverRequest);
```

**💡 See [examples/psr-interop.php](examples/psr-interop.php) for complete working examples.**

### Cookies

[](#cookies)

To avoid `new` calls in your classes and to have the ability to set default cookie settings for you application, there is a `CookieBuilder` class that you can use to create your cookie objects. It has the following methods available:

```
$cookieBuilder->setDefaultDomain($domain); // defaults to NULL
$cookieBuilder->setDefaultPath($path); // defaults to '/'
$cookieBuilder->setDefaultSecure($secure); // defaults to TRUE
$cookieBuilder->setDefaultHttpOnly($httpOnly); // defaults to TRUE
$cookieBuilder->build($name, $value); // returns the cookie object
```

You can use the following methods to manipulate an existing cookie:

```
$cookie->setValue($value);
$cookie->setMaxAge($seconds);
$cookie->setDomain($domain);
$cookie->setPath($path);
$cookie->setSecure($secure);
$cookie->setHttpOnly($httpOnly);
```

The cookie object can the be used with the `HttpResponse` methods `addCookie` and `deleteCookie`.

### Example

[](#example)

```
