PAM HTTP
pushinbr/pam-http is an HTTP application layer for the PAM runtime. Routes read like Express, while the
application structure feels like Laravel: controllers resolved from a container, form requests that validate
input, JSON resources that shape output, and Problem Details for every error.
$app = new Pam\App();
$app->get('/users/{id}', [UserController::class, 'show']) ->where('id', Pam\Api\RouteConstraint::Integer);
$app->listen(3000);The package also ships the pieces a long-lived API needs: request-scoped dependency injection, rate limiting, signed bearer tokens, idempotency keys, response caching, the Arcano ORM integration, OpenAPI generation and an in-memory test client.
Installation
Section titled “Installation”PAM HTTP is a Composer package; it runs inside the PAM runtime and is not a standalone server. Install PAM first.
Create a project from the PAM HTTP starter, which already wires PAM HTTP, Arcano, validation, resources and tests:
pam composer create-project pushinbr/pam-skeleton my-apicd my-apiRequire the package through PAM’s embedded Composer:
pam composer require pushinbr/pam-httppam composer require --dev pushinbr/pam-http-testingThe package requires PHP 8.4 or newer and pushinbr/pam-contracts ^1.1. Optional companions:
| Package | Adds |
|---|---|
pushinbr/arcano |
The Arcano ORM integration. |
pushinbr/pam-http-psr |
PSR-7, PSR-15 and PSR-17 interoperability. |
pushinbr/pam-socket |
Event-oriented WebSockets on the same listener. |
pushinbr/pam-http-testing |
The in-memory test client for any PAM application. |
Your First Application
Section titled “Your First Application”Create an entry file that builds the application and starts the listener:
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Pam\App;use Pam\Http\Request;use Pam\Http\Response;
$app = new App();
$app->get('/', static fn (Request $request, Response $response): Response => $response->json(['message' => 'Hello from PAM']));
$app->get('/users/{id}', static fn (Request $request, Response $response): Response => $response->json(['id' => (int) $request->route('id')]));
$app->listen((int) (getenv('PAM_PORT') ?: 3000));Run it with the PAM CLI:
pam dev index.php # watches files and reloads on changecurl http://127.0.0.1:3000/users/42# {"id":42}In production, pam start index.php runs the same file as a supervised multi-worker cluster. See
Production.
Configuration
Section titled “Configuration”The Application
Section titled “The Application”new App() accepts two optional arguments:
| Argument | Default | Description |
|---|---|---|
discoverPackages |
true |
Register service providers declared by installed Composer packages. See Package discovery. |
container |
null |
A pre-built Pam\Api\Container\Container. A new one is created when omitted. |
Pass discoverPackages: false in tests and console scripts when you want every provider registered explicitly.
The Listener
Section titled “The Listener”listen(int $port, string $host = '127.0.0.1', array $options = []) boots the providers, freezes the
configuration and hands the request handler to the PAM transport. The third argument is passed to the runtime
unchanged, so every listener option works here:
$app->listen(3000, '0.0.0.0', [ 'maxBodyBytes' => 8 * 1024 * 1024, 'requestTimeoutMs' => 15_000, 'trustedProxies' => ['10.0.0.0/8'],]);Typed Environment Configuration
Section titled “Typed Environment Configuration”Configuration reads environment variables once, validates their types and fails during boot when a required
value is missing or malformed:
use Pam\Api\Config\ConfigDefinition;use Pam\Api\Config\Configuration;use Pam\Api\Config\ConfigType;
$config = Configuration::fromEnvironment([ new ConfigDefinition('app.port', 'PAM_PORT', ConfigType::Integer, required: false, default: 3000), new ConfigDefinition('auth.secret', 'AUTH_SECRET', sensitive: true),]);
$app->listen($config->integer('app.port'));ConfigDefinition takes a key, the environment variable, a ConfigType (String = 1, Integer = 2,
Boolean = 3, Float = 4; String by default), whether it is required (default true), a default and a
sensitive flag. Read values with string(), integer(), boolean() and float().
When validation fails, ConfigurationException lists every problem in its errors property; messages name the
variable and the expected type but never echo the supplied value. Use $config->redacted() for diagnostics: it
returns every value with sensitive ones masked. Configuration::fromArray($definitions, $environment) builds the
same object from an array, which is convenient in tests.
Freezing
Section titled “Freezing”Routes, middleware, providers, observers and the error handler can only be registered before the application
handles its first request (or before listen() / boot()). After that, any change throws a LogicException
instead of silently mutating a pipeline that is shared by every request in the worker.
The Persistent Worker Model
Section titled “The Persistent Worker Model”PAM keeps your application in memory between requests. The App, its routes and its singletons are built once
per worker and reused. PAM HTTP gives you two tools to keep requests isolated:
- Scoped bindings. The container creates scoped values once per request and discards them when the request ends, even when it throws. See Container lifetimes.
- Per-request state from middleware. Authentication, tenants and deadlines are stored as scoped instances, never on singletons.
Next Steps
Section titled “Next Steps”- Routing: parameters, constraints, groups and resource routes.
- Controllers & Container: dependency injection, lifetimes and providers.
- Requests & Responses: validation, DTOs, resources and errors.
- Middleware: CORS, rate limiting, idempotency, caching and more.
- Authentication & Tenancy: signed bearer tokens, abilities and tenants.
- Database: the Arcano ORM, migrations and query budgets.
- OpenAPI & Clients: generate a contract and TypeScript, Kotlin or Swift clients.
- Production Toolkit: jobs, events, health checks, resilience and profiling.
- Testing and the API Reference.