Skip to main content

Dirthara Http

Dirthara Http implements the PSR-7 HTTP message interfaces and the PSR-17 factories that create them. Any library that accepts PSR-7 messages can work with these classes, and code written against the PSR interfaces can swap them for another implementation.

ClassImplementsRepresents
RequestRequestInterfaceAn outgoing request, such as one an HTTP client sends.
ServerRequestServerRequestInterfaceAn incoming request as the server received it, with cookies, query parameters, uploaded files, a parsed body, and attributes.
ResponseResponseInterfaceA response with a status code and reason phrase.
UriUriInterfaceA URI, normalized and percent-encoded.
StreamStreamInterfaceA message body backed by a PHP stream resource.
UploadedFileUploadedFileInterfaceA file uploaded with a request.

The StatusCode enum names every registered HTTP status code, so application code can write StatusCode::NotFound instead of 404. The UploadError enum does the same for PHP's upload error codes.

Every message is immutable. A with*() method never changes the object it is called on; it returns a changed copy, or the same object when nothing changes. Always use the returned value.

The package validates what it is given. Header names and values, methods, request targets, status codes, reason phrases, and URI components are checked when they are set, and anything that could split a message or inject a header is refused with an exception.

Start with installation and the getting started guide.