Middleware to generate an UUID and save it in the X-Uuid header

Package info

github.com/middlewares/uuid

pkg:composer/middlewares/uuid

Statistics

Installs: 24 680

Dependents: 3

Suggesters: 0

Stars: 4

Open Issues: 1

v2.1.0 2025-03-23 10:44 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 5e0f862863b4b5a76c880bb3509e99697f6cf385

httpmiddlewareuuidpsr-7psr-15

This package is auto-updated.

Last update: 2026-06-26 17:31:55 UTC


README

👁 Latest Version on Packagist
👁 Software License
👁 Testing
👁 Total Downloads

Middleware to generate an UUID (Universally Unique Identifiers) and save it in the X-Uuid header of the request and response. Useful for debugging purposes.

The UUID generated is compatible with RFC 4122 version 4 using ramsey/uuid for that.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/uuid.

composer require middlewares/uuid

Usage

Dispatcher::run([
	new Middlewares\Uuid(),

 function ($request) {
 //Get the UUID from the request
 echo $request->getHeaderLine('X-Uuid');
 }
]);

//Get the UUID from the response
echo $response->getHeaderLine('X-Uuid');

header

This option allows to configure the header name. By default is X-Uuid.

$uuid = (new Middlewares\Uuid())->header('X-Request-Id');

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.