PHPackages                             milpa/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. [Framework](/categories/framework)
4. /
5. milpa/http

ActiveLibrary[Framework](/categories/framework)

milpa/http
==========

PSR-15-native routing and middleware contracts for the Milpa PHP framework.

v0.1.6(3w ago)01.9k↑104.1%6Apache-2.0PHP &gt;=8.3

Since Jul 6Compare

[ Source](https://github.com/getmilpa/http)[ Packagist](https://packagist.org/packages/milpa/http)[ RSS](/packages/milpa-http/feed)WikiDiscussions Synced 1w ago

READMEChangelog (5)Dependencies (35)Versions (9)Used By (6)

 [   ![Milpa](https://raw.githubusercontent.com/getmilpa/core/main/art/lockup/milpa-lockup-v-color-light.svg)  ](https://github.com/getmilpa)

Milpa HTTP
==========

[](#milpa-http)

> **PSR-15-native routing contracts** for the Milpa PHP framework, built on **`milpa/core`**. One immutable `Route` that is both the `#[Route]` attribute and the matched value; a router that turns a PSR-7 request into a typed `RouteResult` (matched / not-found / method-not-allowed) and never throws for a miss; and typed seams onto PSR-15 handlers and middleware.

[![CI](https://github.com/getmilpa/http/actions/workflows/ci.yml/badge.svg)](https://github.com/getmilpa/http/actions/workflows/ci.yml)[![Packagist](https://camo.githubusercontent.com/5448a7cd9f40e87baa9206b1d9fa7628a831a0fb4c16d4e381c16fadb3e01d3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696c70612f687474702e737667)](https://packagist.org/packages/milpa/http)[![PHP](https://camo.githubusercontent.com/ca03f11ea27dac4dedc8ad56a7bdfc4a9ff5feb825055f9d2983616115076607/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135253230382e332d3737376262342e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/798509b4df525f56802b56f8096862487f08023e3d7561c68656f8dab10d0d6e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4170616368652d2d322e302d626c75652e737667)](LICENSE)[![Docs](https://camo.githubusercontent.com/c6dc6a3411e15b0ac7cc4583e8e6a8144181caedb82f5d98753353decda06d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d4150492532307265666572656e63652d626c75652e737667)](https://getmilpa.github.io/http/)

`milpa/http` carries the contracts for Milpa's web tier — routing and its integration with PSR-15 middleware, and nothing else. It sits one layer above `milpa/core` and speaks the PHP-FIG standards directly: PSR-7 for the request, PSR-15 for handlers and middleware. **No kernel, no concrete router, no middleware runner** — just the typed seams everything binds to.

Install
-------

[](#install)

```
composer require milpa/http
```

What it is
----------

[](#what-it-is)

Milpa splits its surface into small, dependency-light contract packages. `milpa/core` holds the framework-agnostic heart; `milpa/http` adds the **web tier** on top. It is deliberately minimal:

- **`HttpMethod`** — a typed verb enum (`isSafe()`, `isIdempotent()`). No `'GET|POST'` strings.
- **`Route`** — one immutable value that is *also* the `#[Route]` attribute you put on a handler. Path, verbs, name, host, priority, defaults, and per-route middleware — the single source of truth used by both the declaration and the match.
- **`RouterInterface`** — `match(ServerRequestInterface): RouteResult`. A pure function: it never throws for a miss and never builds a response. A 404 or 405 is an expected result.
- **`RouteResult`** — the typed, never-null outcome (`MATCHED` / `NOT_FOUND` / `METHOD_NOT_ALLOWED`), built through named constructors so illegal states can't exist.
- **`HandlerResolverInterface`** &amp; **`MiddlewareResolverInterface`** — the two seams onto PSR-15: turn a matched route's `HandlerReference` into a live `RequestHandlerInterface`, and its per-route middleware `class-string`s into live `MiddlewareInterface`s.
- **`UrlGeneratorInterface`** — reverse routing (name → URL) with a typed `UrlReferenceType`.

**Be honest about scope:** this package ships the **contracts only**. It does not match requests, dispatch middleware, or boot a server by itself — it defines the seams a concrete web runtime implements. Templating and lifecycle events are *not* here: routing is a PSR-15 middleware pipeline, and the view layer is a separate tier.

The shape
---------

[](#the-shape)

Declare a route with the `#[Route]` attribute — it *is* a `Route`, repeatable on one method:

```
use Milpa\Http\HttpMethod;
use Milpa\Http\Routing\Route;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class ShowUser
{
    #[Route('/users/{id}', HttpMethod::GET, name: 'users.show')]
    public function __invoke(ServerRequestInterface $request): ResponseInterface
    {
        // ...
    }
}
```

Match a PSR-7 request and branch on the typed status — no nulls, no exceptions for a miss:

```
use Milpa\Http\Routing\MatchStatus;
use Milpa\Http\Routing\RouteResult;
use Milpa\Http\Routing\RouterInterface;

/** @var RouterInterface $router */
$result = $router->match($request);

$response = match ($result->status) {
    MatchStatus::MATCHED => $handlerResolver
        ->resolve($result->route->handler)
        ->handle($request->withAttribute(RouteResult::ATTRIBUTE, $result)),
    MatchStatus::NOT_FOUND         => $responseFactory->createResponse(404),
    MatchStatus::METHOD_NOT_ALLOWED => $responseFactory->createResponse(405),
};
```

What's inside
-------------

[](#whats-inside)

NamespaceWhat it provides`Milpa\Http``HttpMethod` — the typed HTTP-verb vocabulary`Milpa\Http\Routing``Route` (+ `#[Route]` attribute), `RouteResult`, `MatchStatus`, `HandlerReference`, `RouterInterface`, `HandlerResolverInterface`, `MiddlewareResolverInterface`, `UrlGeneratorInterface`, `UrlReferenceType``Milpa\Http\Exceptions``RoutingExceptionInterface` (marker) + `RouteNotFoundException`, `MissingRouteParametersException` (reverse-routing only)Every public symbol carries a DocBlock. A match miss is never an exception — it is `RouteResult::notFound()`; the exceptions are raised only by URL generation, where an unknown route name or a missing parameter is a bug in the caller.

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

[](#requirements)

- PHP **≥ 8.3**
- [`milpa/core`](https://packagist.org/packages/milpa/core) **^0.2**
- [`psr/http-message`](https://packagist.org/packages/psr/http-message) **^2.0**, [`psr/http-server-handler`](https://packagist.org/packages/psr/http-server-handler) **^1.0**, [`psr/http-server-middleware`](https://packagist.org/packages/psr/http-server-middleware) **^1.0**

Documentation
-------------

[](#documentation)

**Full API reference: [getmilpa.github.io/http](https://getmilpa.github.io/http/)** — generated straight from the source DocBlocks and dressed with the Milpa design system.

Contributing
------------

[](#contributing)

Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Please report security issues via [SECURITY.md](SECURITY.md), and note that this project follows a [Code of Conduct](CODE_OF_CONDUCT.md).

License
-------

[](#license)

[Apache-2.0](LICENSE) © TeamX Agency.

---

Milpa is designed, built, and maintained by **[TeamX Agency](https://teamx.agency/?utm_source=github&utm_medium=readme&utm_campaign=milpa&utm_content=http)**.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance95

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

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 ~4 days

Total

7

Last Release

22d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1993784?v=4)[rodrigomx](/maintainers/rodrigomx)[@rodrigomx](https://github.com/rodrigomx)

---

Tags

httppsr-7phpmiddlewareframeworkroutingpsr-15milpa

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.9k20.0M1.9k](/packages/cakephp-cakephp)[cakephp/authentication

Authentication plugin for CakePHP

1214.3M120](/packages/cakephp-authentication)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[typo3/cms-core

TYPO3 CMS Core

3313.6M5.7k](/packages/typo3-cms-core)[sunrise/http-router

A powerful solution as the foundation of your project.

16852.3k12](/packages/sunrise-http-router)[chubbyphp/chubbyphp-framework

A minimal, highly performant middleware PSR-15 microframework built with as little complexity as possible, aimed primarily at those developers who want to understand all the vendors they use.

13746.3k6](/packages/chubbyphp-chubbyphp-framework)

PHPackages © 2026

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