Uniform::HTMX::PSGI

CPAN version License: MIT

Framework-agnostic htmx adapter for the PSGI/Plack ecosystem.

Uniform::HTMX::PSGI bridges the Uniform::HTMX protocol handler with standard PSGI web applications and Plack response objects. It automatically translates CGI/PSGI environment headers (HTTP_HX_*) and injects accumulated outbound htmx response headers directly into PSGI response data structures.

Installation

Install using cpanm or your preferred CPAN client:

cpanm Uniform::HTMX::PSGI

Synopsis

use Uniform::HTMX::PSGI;

my $app = sub {
    my $env  = shift;
    my $htmx = Uniform::HTMX::PSGI->new($env);

    # Inspect incoming htmx request attributes
    if ($htmx->is_htmx) {
        my $target = $htmx->target;
        
        # Queue outbound htmx response headers
        $htmx->res_trigger('itemSaved', { id => 42 })
             ->res_reswap('innerHTML');
    }

    my $res = [ 200, [ 'Content-Type' => 'text/html' ], [ '<div>Saved!</div>' ] ];

    # Inject queued headers into the PSGI response
    return $htmx->apply($res);
};

Key Features

Local Development & Testing

Run the test suite using prove:

prove -Ilib t/

To run the interactive test application locally:

plackup -Ilib app.psgi

This software is Copyright (c) 2026 by Joshua S. Day <HAX@cpan.org>.

This is free software, licensed under:

The MIT (X11) License