PHPackages                             juanchosl/httpdata - 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. juanchosl/httpdata

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

juanchosl/httpdata
==================

Little methods collection in order to create http request and responses using the PSR standards from PHP-FIG definitions

1.0.7(4mo ago)12733MITPHPPHP ^8.0

Since Apr 22Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/JuanchoSL/HttpData)[ Packagist](https://packagist.org/packages/juanchosl/httpdata)[ Docs](https://github.com/JuanchoSL/httpdata)[ RSS](/packages/juanchosl-httpdata/feed)WikiDiscussions 1.0 Synced 1mo ago

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

HttpData
========

[](#httpdata)

Description
-----------

[](#description)

This library implements the definitions of the different elements involved in data transmissions such as HTTP, applying the interfaces defineds in PSRS 7 and 17, adding the extra objects used and ensuring compliance with the requirements that allow to give the necessary stability to our application, being able to implement for third -party bookstores without the need to adapt our business logic to a new implementation that could modify its consumption or internal structure.

Install
-------

[](#install)

```
composer require juanchosl/httpdata
```

Contents
--------

[](#contents)

Includes the needed implementations for a data transmission. You can view his definitions for each required block on the official page

### PSR-7 Messages

[](#psr-7-messages)

The Containers folder/namespace, implementation of elements included into [PSR-7](https://www.php-fig.org/psr/psr-7)

- Message base class
- Request (extends Message, Client side)
- ServerRequest (extends Request, Server side)
- Response (extends Message)
- Streams
- Uris
- Uploaded files

### PSR-17 Factories

[](#psr-17-factories)

The Factories folder/namespace, defines how create the objects, ensuring the full compatibility between libraries, applying the [PSR-17](https://www.php-fig.org/psr/psr-17)

- Server request
- Client request
- Response
- Streams
- Uris
- Uploaded files

#### Server factory

[](#server-factory)

As an extra, we can create a full formatted Server request, ir order to retrieve a standard object from

- using the **fromGlobals** method and adquire data from **\_SERVER** superglobal constant without pass any parameter
- using the **fromRequest** method, using a pre created Request as parameter, usefull for tests and console actions

#### Uri factory

[](#uri-factory)

As an extra, we can create a full formatted URI, ir order to retrieve a standard object from

- using the **fromGlobals** method and adquire data from **\_SERVER** superglobal constant without pass any parameter

### FIG Message utils

[](#fig-message-utils)

The library includes the messages utils from FIGs of PHP, includes the

#### RequestMethodsInterface

[](#requestmethodsinterface)

Constants for the distincts http available methods

- GET
- POST
- PUT
- PATCH
- DELETE
- HEAD
- OPTIONS
- PURGE
- TRACE
- CONNECT

#### StatusCodesInterface

[](#statuscodesinterface)

All the standard status codes, for use across your system

### Body String creators

[](#body-string-creators)

In order to create standard sender bodies, are providing 2 tools in order to create *multipart/form-data* and *application/x-www-form-urlencoded*

#### URL Encoder

[](#url-encoder)

Available for GET or BODY params, creating an urlencoded string from any array type

```
use JuanchoSL\HttpData\Bodies\Creators\UrlencodedCreator;

echo (new UrlencodedCreator)->appendData([
    'form' => [
        'name' => "nombre",
        'surname' => "apellidos"
    ]
]);

#> form%5Bname%5D=nombre&form%5Bsurname%5D=apellidos
```

#### Multipart Encoder

[](#multipart-encoder)

Available for BODY params, creating multipar/form-data string from any array type

```
use JuanchoSL\HttpData\Bodies\Creators\MultipartCreator;

echo (new MultipartCreator(md5(uniqid())))->appendData([
    'form' => [
        'name' => "nombre",
        'surname' => "apellidos"
    ]
]);

/*
--47608c536770a84a371e08a0ffd92e95
Content-Disposition: form-data; name="form[name]"

nombre
--47608c536770a84a371e08a0ffd92e95
Content-Disposition: form-data; name="form[surname]"

apellidos
--47608c536770a84a371e08a0ffd92e95--
*/
```

Can add files from 3 distincts formats too

```
use JuanchoSL\HttpData\Bodies\Creators\MultipartCreator;

$file = realpath('../../file.txt');
$data = [
    'form' => [
        'name' => "nombre",
        'surname' => "apellidos"
    ],
    'file' => [
        new CURLStringFile(file_get_contents($file), basename($file), 'text/plain'),
        new CURLFile($file, 'text/plain', basename($file)),
        '@' . $file
    ]
];
echo (new MultipartCreator(md5(uniqid())))->appendData($data);
/*
--b660ef4adf655b4043ab99cd21c6fa92
Content-Disposition: form-data; name="form[name]"

nombre
--b660ef4adf655b4043ab99cd21c6fa92
Content-Disposition: form-data; name="form[surname]"

apellidos
--b660ef4adf655b4043ab99cd21c6fa92
Content-Disposition: form-data; name="file[]"; filename="file.txt"
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-Length: 95

esto es un texto de ejemplo desde un fichero
--b660ef4adf655b4043ab99cd21c6fa92
Content-Disposition: form-data; name="file[]"; filename="file.txt"
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-Length: 95

esto es un texto de ejemplo desde un fichero
--b660ef4adf655b4043ab99cd21c6fa92
Content-Disposition: form-data; name="file[]"; filename="file.txt"
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-Length: 95

esto es un texto de ejemplo desde un fichero
--b660ef4adf655b4043ab99cd21c6fa92--
*/
```

### Body String reverse parsing

[](#body-string-reverse-parsing)

In order to receive standard bodies and parse to use it, you can read and convert the *multipart/form-data* and *application/x-www-form-urlencoded* string body contents

#### Multipart decoder

[](#multipart-decoder)

Available for BODY contents, reading multipar/form-data string to array type

```
use JuanchoSL\HttpData\Bodies\Parsers\MultipartReader;

$str = getBody();
$body_parsed = (new MultipartReader($body))->getBodyParams();
echo "" . print_r($body_parsed, true);

Array
(
    [form] => Array
        (
            [name] => nombre
            [surname] => apellidos
        )

)
```

Can extract files too

```
use JuanchoSL\HttpData\Bodies\Parsers\MultipartReader;

$str = getBody();
$body_parsed = (new MultipartReader($body))->getBodyFiles();
echo "" . print_r($body_parsed, true);
Array
(
    [file] => Array
        (
            [tmp_name] => Array
                (
                    [0] => C:\Users\juan\AppData\Local\Temp\php474B.tmp
                    [1] => C:\Users\juan\AppData\Local\Temp\php474C.tmp
                    [2] => C:\Users\juan\AppData\Local\Temp\php474D.tmp
                )

            [size] => Array
                (
                    [0] => 46
                    [1] => 46
                    [2] => 46
                )

            [error] => Array
                (
                    [0] => 0
                    [1] => 0
                    [2] => 0
                )

            [name] => Array
                (
                    [0] => file.txt
                    [1] => file.txt
                    [2] => file.txt
                )

            [type] => Array
                (
                    [0] => text/plain
                    [1] => text/plain
                    [2] => text/plain
                )

        )
)
```

We can extract both value groups, as array, with data into index 0 and files into index 1

```
[$_POST, $_FILES] = (new MultipartReader($body))->getBodyParts();
```

Or populate to globals directly in order to use it for PATCH and PUT requests

```
(new MultipartReader($body))->toGlobals();
```

### Full Message parser

[](#full-message-parser)

Extending previous tools, that only parse the body contents, now we can parse the full info from a message (Request or Response), in order to extract the message info and headers. They can be usefull for convert a raw message string to a standard entity and process it with existing tools.

#### Request parser

[](#request-parser)

Convert an inbound raw http request to a Request parse, as example, can be used for Web Sockets handshake start

```
$raw_message = "GET / HTTP/1.1
Sec-WebSocket-Key: adasd78a8sdad7as897hhjkh
Sec-WebSocket-Version: 13
";

$message = new RequestReader((new StreamFactory())->createStream($raw_message));
$message->toPostGlobals();
```

#### Response parser

[](#response-parser)

Convert an inbound raw http response to a Response container, as example, can be used for Web Sockets handshake response

```
$raw_response = "HTTP/1.1 101 Web Socket Protocol Handshake
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Origin: https://host.docker.internal
Sec-WebSocket-Location: wss://host.docker.internal:8001
Sec-WebSocket-Version: 13
Sec-WebSocket-Accept:dasdkladasjdlkausdioaoadads0d

";

$stream = (new StreamFactory())->createStream($raw_response);
$response = new ResponseReader($stream);
$response = $response();
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance76

Regular maintenance activity

Popularity15

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Every ~32 days

Total

9

Last Release

129d ago

PHP version history (3 changes)1.0.0PHP ^7.1 || ^8.0

1.0.2PHP ^8.1

1.0.6PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd6d3dea7eb469817524c42a80683e95793ed4800a6794366503355af046a726?d=identicon)[Juanchosl](/maintainers/Juanchosl)

---

Top Contributors

[![JuanchoSL](https://avatars.githubusercontent.com/u/18701207?v=4)](https://github.com/JuanchoSL "JuanchoSL (95 commits)")

---

Tags

httpresponserequeststreammessageuripsr7psr17psr18

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juanchosl-httpdata/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[pdeans/http

PSR-7 cURL HTTP client with support for PSR-17 HTTP factories.

1466.2k3](/packages/pdeans-http)[workerman/psr7

PSR-7 message implementation that also provides common utility methods

1079.8k10](/packages/workerman-psr7)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)[chillerlan/php-httpinterface

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

1417.1k5](/packages/chillerlan-php-httpinterface)

PHPackages © 2026

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