PHPackages                             marcguyer/version-middleware - 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. marcguyer/version-middleware

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

marcguyer/version-middleware
============================

PSR-7 middleware for managing routable versioning.

0.0.1(7y ago)104672[1 PRs](https://github.com/marcguyer/version-middleware/pulls)BSD-3-ClausePHPPHP ^7.1

Since Jan 20Pushed 2y ago3 watchersCompare

[ Source](https://github.com/marcguyer/version-middleware)[ Packagist](https://packagist.org/packages/marcguyer/version-middleware)[ RSS](/packages/marcguyer-version-middleware/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (10)Versions (2)Used By (0)

Versioning for PSR-7 apps
=========================

[](#versioning-for-psr-7-apps)

[![Build Status](https://camo.githubusercontent.com/567a7a02f684f1b1c1959dc5781d15fbb5e4446fdd304225a554bd6be4710a51/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6d61726367757965722f76657273696f6e2d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://secure.travis-ci.org/marcguyer/version-middleware)[![Coverage Status](https://camo.githubusercontent.com/188c969cd5073399c034234d7d2e46a635364491648200fb19e5b20c6bea9292/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d61726367757965722f76657273696f6e2d6d6964646c65776172652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/marcguyer/version-middleware?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/eb9eedb4fbf234fedf667e5092c1809a06f3d5c63eb876dfa044be9b3747c605/68747470733a2f2f706f7365722e707567782e6f72672f6d61726367757965722f76657273696f6e2d6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/marcguyer/version-middleware)[![Total Downloads](https://camo.githubusercontent.com/bb3d78f8e308d81da087ff33df93f5b051c993f8daaa1df301b686ee26e08dae/68747470733a2f2f706f7365722e707567782e6f72672f6d61726367757965722f76657273696f6e2d6d6964646c65776172652f646f776e6c6f616473)](https://packagist.org/packages/marcguyer/version-middleware)

Provides version detection, making versioned resource routing possible in PSR-7 applications.

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

[](#installation)

Install this library using composer:

```
$ composer require marcguyer/version-middleware
```

Composer will ask if you'd like to inject the ConfigProvider if you're using `zendframework/zend-component-installer`. Answer yes or config it by hand.

Usage
-----

[](#usage)

### Config

[](#config)

See the [ConfigProvider](src/ConfigProvider.php) for config defaults. You may override using the `versioning` key. For example, the default version is `1`. You might release a new version and set the default version to `2`. Any clients not specifying a version via path or header will then be hitting version 2 resources.

### Add to pipeline

[](#add-to-pipeline)

Wire this middleware into your pipeline before routing. An example using a Zend Expressive pipeline:

```
...
$app->pipe(ServerUrlMiddleware::class);
...
$app->pipe(Psr7Versioning\VersionMiddleware::class);
...
$app->pipe(RouteMiddleware::class);
...
```

### Routing

[](#routing)

Now, you can route based on the rewritten URI path. For example, in Expressive:

```
$app->get('/api/v1/ping', Api\Handler\PingHandler::class, 'api.ping');
$app->get('/api/v2/ping', Api\V2\Handler\PingHandler::class, 'api.v2.ping');
```

### Namespaced version

[](#namespaced-version)

Now, using the above routing example, assuming your v1 Ping is in namespace `Api\Handler`, you may set the namespace for v2 Ping to be `Api\V2\Handler` and extend the v1 handler. Any reference to services, models, other middleware will follow that namespace. Or, copy everything you want to be in the new version into a new namespace entirely.

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

[](#contributing)

### Docker Image

[](#docker-image)

The `Dockerfile` in the repo can be used to create a lightweight image locally for running tests and other composer scripts:

```
docker build --tag [your_chosen_image_name] .
```

### Run tests

[](#run-tests)

```
docker run --rm -it -v $(pwd):/app [your_chosen_image_name] composer test
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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

2672d ago

### Community

Maintainers

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

---

Top Contributors

[![marcguyer](https://avatars.githubusercontent.com/u/35496?v=4)](https://github.com/marcguyer "marcguyer (8 commits)")[![Repkit](https://avatars.githubusercontent.com/u/2531428?v=4)](https://github.com/Repkit "Repkit (2 commits)")

---

Tags

middlewarephppsr-7psr-7phpmiddlewareapipsr7versioningZendFrameworkzfexpressive

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/marcguyer-version-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/marcguyer-version-middleware/health.svg)](https://phpackages.com/packages/marcguyer-version-middleware)
```

###  Alternatives

[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[mtymek/blast-base-url

PSR-7 middleware and helpers for working with base URL.

1054.0k3](/packages/mtymek-blast-base-url)

PHPackages © 2026

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