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

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

maplephp/http
=============

MaplePHP/Http is a powerful and easy-to-use PHP library that fully supports the PSR-7 HTTP message and PSR-18: HTTP Client.

v2.2.1(3mo ago)362918Apache-2.0PHPPHP &gt;=8.2CI passing

Since Nov 29Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/MaplePHP/Http)[ Packagist](https://packagist.org/packages/maplephp/http)[ Docs](https://wazabii.se)[ RSS](/packages/maplephp-http/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (10)Versions (20)Used By (8)

MaplePHP - A Full-Featured PSR-7 Compliant HTTP Library
=======================================================

[](#maplephp---a-full-featured-psr-7-compliant-http-library)

**MaplePHP/Http** is a powerful and easy-to-use PHP library that fully supports the PSR-7 HTTP message interfaces. It simplifies handling HTTP requests, responses, streams, URIs, and uploaded files, making it an excellent choice for developers who want to build robust and interoperable web applications.

With MaplePHP, you can effortlessly work with HTTP messages while adhering to modern PHP standards, ensuring compatibility with other PSR-7 compliant libraries.

Why Choose MaplePHP?
--------------------

[](#why-choose-maplephp)

- **Full PSR-7 Compliance**: Seamlessly integrates with other PSR-7 compatible libraries and frameworks.
- **User-Friendly API**: Designed with developers in mind for an intuitive and straightforward experience.
- **Comprehensive Functionality**: Handles all aspects of HTTP messaging, including requests, responses, streams, URIs, and file uploads.
- **Flexible and Extensible**: Easily adapts to projects of any size and complexity.

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

[](#installation)

Install MaplePHP via Composer:

```
composer require maplephp/http
```

### Handling HTTP Requests

[](#handling-http-requests)

#### Creating a Server Request

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

To create a server request, use the `ServerRequest` class:

```
use MaplePHP\Http\Environment;use MaplePHP\Http\ServerRequest;use MaplePHP\Http\Uri;

// Create an environment instance (wraps $_SERVER)
$env = new Environment();

// Create a URI instance from the environment
$uri = new Uri($env->getUriParts());

// Create the server request
$request = new ServerRequest($uri, $env);
```

#### Accessing Request Data

[](#accessing-request-data)

You can easily access various parts of the request:

```
// Get the HTTP method
$method = $request->getMethod(); // e.g., GET, POST

// Get request headers
$headers = $request->getHeaders();

// Get a specific header
$userAgent = $request->getHeaderLine('User-Agent');

// Get query parameters
$queryParams = $request->getQueryParams();

// Get parsed body (for POST requests)
$parsedBody = $request->getParsedBody();

// Get uploaded files
$uploadedFiles = $request->getUploadedFiles();

// Get server attributes
$attributes = $request->getAttributes();
```

#### Modifying the Request

[](#modifying-the-request)

Requests are immutable; methods that modify the request return a new instance:

```
// Add a new header
$newRequest = $request->withHeader('X-Custom-Header', 'MyValue');

// Change the request method
$newRequest = $request->withMethod('POST');

// Add an attribute
$newRequest = $request->withAttribute('user_id', 123);
```

### Managing HTTP Responses

[](#managing-http-responses)

#### Creating a Response

[](#creating-a-response)

Create a response using the `Response` class:

```
use MaplePHP\Http\Response;use MaplePHP\Http\Stream;

// Create a stream for the response body
$body = new Stream('php://temp', 'rw');

// Write content to the body
$body->write('Hello, world!');
$body->rewind();

// Create the response with the body
$response = new Response($body);
```

#### Setting Status Codes and Headers

[](#setting-status-codes-and-headers)

You can set the HTTP status code and headers:

```
// Set the status code to 200 OK
$response = $response->withStatus(200);

// Add headers
$response = $response->withHeader('Content-Type', 'text/plain');

// Add multiple headers
$response = $response->withAddedHeader('X-Powered-By', 'MaplePHP');
```

#### Sending the Response

[](#sending-the-response)

To send the response to the client:

```
// Output headers
foreach ($response->getHeaders() as $name => $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

// Output status line
header(sprintf(
    'HTTP/%s %s %s',
    $response->getProtocolVersion(),
    $response->getStatusCode(),
    $response->getReasonPhrase()
));

// Output body
echo $response->getBody();
```

### Working with Streams

[](#working-with-streams)

Streams are used for the message body in requests and responses.

#### Creating a Stream

[](#creating-a-stream)

Reading and Writing with stream

```
use MaplePHP\Http\Stream;

// Create a stream from a file
//$fileStream = new Stream('/path/to/file.txt', 'r');

// Create a stream from a string
$memoryStream = new Stream(Stream::MEMORY);
//$memoryStream = new Stream('php://memory', 'r+'); // Same as above
$memoryStream->write('Stream content');

// Write to the stream
$memoryStream->write(' More content');

// Read from the stream
$memoryStream->rewind();
echo $memoryStream->getContents();
// Result: 'Stream content More content'
```

#### Using Streams in Requests and Responses

[](#using-streams-in-requests-and-responses)

```
// Set stream as the body of a response
$response = $response->withBody($memoryStream);
```

### Manipulating URIs

[](#manipulating-uris)

URIs are used to represent resource identifiers.

#### Creating and Modifying URIs

[](#creating-and-modifying-uris)

```
// Create a URI instance
$uri = new Uri('http://example.com:8000/path?query=value#fragment');

// Modify the URI
$uri = $uri->withScheme('https')
            ->withUserInfo('guest', 'password123')
            ->withHost('example.org')
            ->withPort(8080)
            ->withPath('/new-path')
            ->withQuery('query=newvalue')
            ->withFragment('section1');

// Convert URI to string
echo $uri; // Outputs the full URI
//Result: https://guest:password123@example.org:8080/new-path?query=newvalue#section1
```

#### Accessing URI Components

[](#accessing-uri-components)

```
echo $uri->getScheme();     // 'http'
echo $uri->getUserInfo();   // 'guest:password123'
echo $uri->getHost();       // 'example.org'
echo $uri->getPath();       // '/new-path'
echo $uri->getQuery();      // 'key=newvalue'
echo $uri->getFragment();   // 'section1'
echo $uri->getAuthority();  // 'guest:password123@example.org:8080'
```

### Handling Uploaded Files

[](#handling-uploaded-files)

Manage file uploads with ease using the `UploadedFile` class.

#### Accessing Uploaded Files

[](#accessing-uploaded-files)

```
// Get uploaded files from the request
$uploadedFiles = $request->getUploadedFiles();

// Access a specific uploaded file
$uploadedFile = $uploadedFiles['file_upload'];

// Get file details
$clientFilename = $uploadedFile->getClientFilename();
$clientMediaType = $uploadedFile->getClientMediaType();

// Move the uploaded file to a new location
$uploadedFile->moveTo('/path/to/uploads/' . $clientFilename);
```

### Using the HTTP Client

[](#using-the-http-client)

Send HTTP requests using the built-in HTTP client.

#### Sending a Request

[](#sending-a-request)

```
// Init request client
$client = new Client([CURLOPT_HTTPAUTH => CURLAUTH_DIGEST]); // Pass on Curl options

// Create request data
$request = new Request(
    "POST", // The HTTP Method (GET, POST, PUT, DELETE, PATCH)
    "https://admin:mypass@example.com:443/test.php", // The Request URI
    ["customHeader" => "lorem"], // Add Headers, empty array is allowed
    ["email" => "john.doe@example.com"] // Post data
);

// Pass request data to client and POST
$response = $client->sendRequest($request);
if ($response->getStatusCode() === 200) {
    // Parse the response body
    $data = json_decode($response->getBody()->getContents(), true);
    // Use the data
    echo 'User Name: ' . $data['name'];
} else {
    echo 'Error: ' . $response->getReasonPhrase();
}
```

---

Input
=====

[](#input)

A simple, secure static helper class for reading and sanitizing `$_GET` and `$_POST` values in PHP. Part of the [MaplePHP HTTP](https://github.com/MaplePHP/Http) library.

### Checking if a key exists

[](#checking-if-a-key-exists)

```
// Check in either $_GET or $_POST
Input::has('name');

// Check only in $_GET
Input::hasGet('page');

// Check only in $_POST
Input::hasPost('email');
```

---

### Reading encoded (safe) values

[](#reading-encoded-safe-values)

Values are automatically HTML-encoded to prevent XSS. Returns `null` if the key does not exist.

```
// From $_GET
$page = Input::get('page');

// From $_POST
$email = Input::post('email');

// From $_GET or $_POST (GET takes priority)
$id = Input::request('id');

// With a fallback default
$page = Input::get('page', '1');
```

---

### Reading raw (unencoded) values

[](#reading-raw-unencoded-values)

Use raw methods when you need the original unmodified value, or when working with array inputs.

```
// Scalar raw value
$name = Input::getRaw('name');

// Array input e.g. $_POST['tags'][]
$tags = Input::postRaw('tags');

// With a fallback default
$filters = Input::getRaw('filters', []);
```

> **Note:** Raw values are not sanitized. Make sure to validate or sanitize them before use.

---

### Reading all input

[](#reading-all-input)

```
// All raw merged input from $_GET and $_POST (POST takes priority)
$data = Input::all();

// All encoded merged input, including nested arrays
$data = Input::allEncoded();
```

---

Conclusion
----------

[](#conclusion)

**MaplePHP/Http** is a comprehensive library that makes working with HTTP in PHP a breeze. Its full PSR-7 compliance ensures that your applications are built on solid, modern standards, promoting interoperability and maintainability.

Whether you're handling incoming requests, crafting responses, manipulating URIs, working with streams, or managing file uploads, MaplePHP provides a clean and intuitive API that simplifies your development process.

Get started today and enhance your PHP applications with MaplePHP!

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance82

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 95.8% 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 ~49 days

Recently: every ~5 days

Total

18

Last Release

111d ago

Major Versions

v1.2.3 → v2.0.02026-01-12

PHP version history (2 changes)v1.0.0PHP &gt;=8.0

v2.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/724b188e785081275926c5b9c07082e2b3f4afb797efdda61eb1630457e17824?d=identicon)[wazabii](/maintainers/wazabii)

---

Top Contributors

[![wazabii8](https://avatars.githubusercontent.com/u/6400238?v=4)](https://github.com/wazabii8 "wazabii8 (46 commits)")[![CreativeWaDev](https://avatars.githubusercontent.com/u/153771800?v=4)](https://github.com/CreativeWaDev "CreativeWaDev (2 commits)")

---

Tags

clientcurlheadershttpmessagingphppsr-7psr7-httpresponseserverstreamuploadhttprequestpsr-7http-messagestreammessageclientpsr-18serverheadersupload

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

185702.8k44](/packages/laudis-neo4j-php-client)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

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

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

1418.3k8](/packages/chillerlan-php-httpinterface)

PHPackages © 2026

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