Search by

webservco / http-request-service

ariademur

A PHP component/library. Helpers for reading the method, body, headers, Accept list and route parts of a request.

Package info

github.com/webservco/http-request-service

Homepage

pkg:composer/webservco/http-request-service

Statistics

Installs: 434

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

v2.3.0 2026-10-11 16:34 UTC

This package is auto-updated.

Last update: 2026-10-11 16:45:39 UTC


README

A PHP component/library. Please see webservco/sandbox for an example project using these types of components.

Helpers for reading the method, body, headers, Accept list and route parts of a request.

  • Related: webservco/dependency-container (getRequestServiceContainer()), webservco/middleware (sets the route parts read here)

Installation

composer require webservco/http-request-service

Usage

Get the services from the container instead of creating them one by one.

// \WebServCo\Http\Contract\Message\Request\Container\RequestServiceContainerInterface
$requestServiceContainer = $applicationDependencyContainer->getRequestServiceContainer();

// Route /example/test/foo: part 1 is "example", part 3 is "foo", missing parts are null.
$id = $requestServiceContainer->getServerRequestAttributeService()->getRoutePart(3, $request);

$contentType = $requestServiceContainer->getRequestHeaderService()->getHeaderValue('Content-Type', $request);

$hasBody = $requestServiceContainer->getRequestBodyService()->canHaveRequestBody($request);

Contracts

Interface Implementation Purpose
Contract\Message\Request\Container\RequestServiceContainerInterface Container\Message\Request\RequestServiceContainer Access to all the services below.
Contract\Message\Request\Server\ServerRequestAttributeServiceInterface Service\Message\Request\Server\ServerRequestAttributeService getRoutePart() from the routePart.N request attributes.
Contract\Message\Request\Server\ServerHeadersAcceptServiceInterface Service\Message\Request\Server\ServerHeadersAcceptService Reads the Accept header, sorts it by quality and drops types with q=0.
Contract\Message\Request\RequestHeaderServiceInterface Service\Message\Request\RequestHeaderService First value of a header. Throws an UnexpectedValueException if the header is missing.
Contract\Message\Request\RequestBodyServiceInterface Service\Message\Request\RequestBodyService Whether the method allows a body.
Contract\Message\Request\Method\RequestMethodServiceInterface Service\Message\Request\Method\RequestMethodService Validates the HTTP method.

Namespaces are relative to WebServCo\Http\.

Development

# Start project.
ddev start
# Install dependencies.
ddev c u
# Run all validations.
ddev c c
# Run unit tests.
ddev c test:dox

License

MIT