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

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

lighthouse/http
===============

PSR-7 HTTP Message and PSR-17 HTTP Factory implementation for the Lighthouse framework

v0.1.0(6mo ago)0114MITPHPPHP ^8.2CI passing

Since Dec 17Pushed 6mo agoCompare

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

READMEChangelogDependencies (5)Versions (2)Used By (4)

Lighthouse HTTP
===============

[](#lighthouse-http)

A PSR-7 HTTP Message and PSR-17 HTTP Factory implementation for the Lighthouse framework.

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

[](#installation)

```
composer require lighthouse/http
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher

Features
--------

[](#features)

- Full PSR-7 (HTTP Message) implementation
- Full PSR-17 (HTTP Factories) implementation
- Immutable value objects
- Strict typing throughout
- Zero dependencies beyond PSR interfaces

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

[](#quick-start)

### Creating a Request

[](#creating-a-request)

```
use Lighthouse\Http\Request;

// Simple request
$request = new Request('GET', 'https://api.example.com/users');

// Request with headers and body
$request = new Request(
    method: 'POST',
    uri: 'https://api.example.com/users',
    headers: [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
    ],
    body: json_encode(['name' => 'John'])
);
```

### Creating a Server Request from Globals

[](#creating-a-server-request-from-globals)

```
use Lighthouse\Http\ServerRequest;

// Create from PHP superglobals
$request = ServerRequest::fromGlobals();

// Access request data
$method = $request->getMethod();
$path = $request->getUri()->getPath();
$query = $request->getQueryParams();
$body = $request->getParsedBody();
```

### Creating a Response

[](#creating-a-response)

```
use Lighthouse\Http\Response;

// Simple response
$response = new Response(200);

// Response with body
$response = new Response(
    statusCode: 200,
    headers: ['Content-Type' => 'application/json'],
    body: json_encode(['status' => 'ok'])
);

// Check response status
if ($response->isSuccessful()) {
    // 2xx response
}
```

### Working with Streams

[](#working-with-streams)

```
use Lighthouse\Http\Stream;

// Create from string
$stream = Stream::create('Hello, World!');

// Create from file
$stream = Stream::createFromFile('/path/to/file.txt', 'r');

// Read and write
$content = $stream->getContents();
$stream->write('more data');
```

### Working with URIs

[](#working-with-uris)

```
use Lighthouse\Http\Uri;

$uri = new Uri('https://user:pass@example.com:8080/path?query=value#fragment');

$scheme = $uri->getScheme();     // 'https'
$host = $uri->getHost();         // 'example.com'
$port = $uri->getPort();         // 8080
$path = $uri->getPath();         // '/path'
$query = $uri->getQuery();       // 'query=value'

// Modify (returns new instance)
$newUri = $uri->withPath('/new-path')->withQuery('new=query');
```

### Using Factories (PSR-17)

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

```
use Lighthouse\Http\Factory\RequestFactory;
use Lighthouse\Http\Factory\ResponseFactory;
use Lighthouse\Http\Factory\StreamFactory;
use Lighthouse\Http\Factory\UriFactory;

$requestFactory = new RequestFactory();
$request = $requestFactory->createRequest('GET', 'https://example.com');

$responseFactory = new ResponseFactory();
$response = $responseFactory->createResponse(200, 'OK');

$streamFactory = new StreamFactory();
$stream = $streamFactory->createStream('content');

$uriFactory = new UriFactory();
$uri = $uriFactory->createUri('https://example.com');
```

PSR-7 Interfaces Implemented
----------------------------

[](#psr-7-interfaces-implemented)

InterfaceImplementation`MessageInterface``Message` (abstract)`RequestInterface``Request``ServerRequestInterface``ServerRequest``ResponseInterface``Response``StreamInterface``Stream``UriInterface``Uri``UploadedFileInterface``UploadedFile`PSR-17 Interfaces Implemented
-----------------------------

[](#psr-17-interfaces-implemented)

InterfaceImplementation`RequestFactoryInterface``RequestFactory``ServerRequestFactoryInterface``ServerRequestFactory``ResponseFactoryInterface``ResponseFactory``StreamFactoryInterface``StreamFactory``UriFactoryInterface``UriFactory``UploadedFileFactoryInterface``UploadedFileFactory`Immutability
------------

[](#immutability)

All PSR-7 objects are immutable. Methods that appear to modify the object actually return a new instance:

```
$request = new Request('GET', 'https://example.com');

// This returns a NEW request - doesn't modify original
$newRequest = $request->withMethod('POST');

$request->getMethod();    // Still 'GET'
$newRequest->getMethod(); // 'POST'
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

Part of the Lighthouse Framework
--------------------------------

[](#part-of-the-lighthouse-framework)

This package is part of the [Lighthouse Framework](https://github.com/lighthouse-php), an educational PHP framework designed to teach how modern frameworks work internally.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance66

Regular maintenance activity

Popularity5

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

198d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13813941?v=4)[Richard Trujillo](/maintainers/richardtrujillotorres)[@RichardTrujilloTorres](https://github.com/RichardTrujilloTorres)

---

Top Contributors

[![RichardTrujilloTorres](https://avatars.githubusercontent.com/u/13813941?v=4)](https://github.com/RichardTrujilloTorres "RichardTrujilloTorres (3 commits)")

---

Tags

httpresponserequestpsr-7messagefactorypsr-17lighthouse

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lighthouse-http/health.svg)

```
[![Health](https://phpackages.com/badges/lighthouse-http/health.svg)](https://phpackages.com/packages/lighthouse-http)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k747.1M2.7k](/packages/psr-http-factory)[chillerlan/php-httpinterface

A PSR-7/17/18 http message/client implementation

1418.3k8](/packages/chillerlan-php-httpinterface)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28150.5k](/packages/phpro-http-tools)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

157.1k](/packages/art4-requests-psr18-adapter)[sunrise/http-message

An HTTP message implementation based on PSR-7, PSR-17 and RFC-7230.

18114.6k17](/packages/sunrise-http-message)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
