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

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

tiny-blocks/http
================

Implements PSR-7, PSR-15, PSR-17 and PSR-18 HTTP primitives for PHP, with a fluent response builder, cookies, cache control, and a PSR-18 client facade.

6.3.0(2w ago)323.3k↓79.9%6MITPHPPHP ^8.5CI passing

Since Aug 6Pushed 1w agoCompare

[ Source](https://github.com/tiny-blocks/http)[ Packagist](https://packagist.org/packages/tiny-blocks/http)[ Docs](https://github.com/tiny-blocks/http)[ RSS](/packages/tiny-blocks-http/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (57)Versions (39)Used By (6)

Http
====

[](#http)

[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://github.com/tiny-blocks/http/blob/main/LICENSE)

- [Overview](#overview)
- [Installation](#installation)
- [How to use](#how-to-use)
    - [Server](#server)
        - [Decoding a request](#decoding-a-request)
        - [Creating a response](#creating-a-response)
        - [Pagination links](#pagination-links)
        - [Setting cookies](#setting-cookies)
        - [Status code](#status-code)
    - [Client](#client)
        - [Building Http with a PSR-18 client and PSR-17 factories](#building-http-with-a-psr-18-client-and-psr-17-factories)
        - [Making a request](#making-a-request)
        - [Reading the response](#reading-the-response)
        - [Query parameters](#query-parameters)
        - [Custom headers and content type](#custom-headers-and-content-type)
        - [Default headers](#default-headers)
        - [Setting the User-Agent](#setting-the-user-agent)
        - [Error handling](#error-handling)
        - [Configuring timeouts](#configuring-timeouts)
        - [Testing with InMemoryTransport](#testing-with-inmemorytransport)
        - [Extending with custom transports](#extending-with-custom-transports)
- [FAQ](#faq)
- [License](#license)
- [Contributing](#contributing)

Overview
--------

[](#overview)

The library covers both sides of an HTTP exchange:

- **Server side** (`TinyBlocks\Http\Server`) - decodes a PSR-7 `ServerRequestInterface` into typed accessors and builds outgoing `ResponseInterface` instances with cookies, cache-control, and status codes.
- **Client side** (`TinyBlocks\Http\Client`) - composes outbound requests, sends them through a `Transport` port backed by any PSR-18 client, and exposes responses with typed body and header access.

Shared primitives at `TinyBlocks\Http\`: `Method`, `Code`, `Headers`, `Headerable`, `ContentType`, `MimeType`, `Charset`, `Cookie`, `SameSite`, `CacheControl`, `ResponseCacheDirectives`, `Link`, `LinkRelation`, `UserAgent`.

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

[](#installation)

```
composer require tiny-blocks/http
```

How to use
----------

[](#how-to-use)

### Server

[](#server)

#### Decoding a request

[](#decoding-a-request)

Wrap a PSR-7 `ServerRequestInterface` and read typed fields from the body, route parameters, and query string.

```
