README.md

PSX Http

About

This library contains well designed interfaces to describe HTTP message,
middleware and client classes. It contains also corresponding reference
implementations which can be used by every app which needs a solid HTTP stack.
They are used by the PSX framework and
Fusio.

We are aware that this overlaps with PSR-7 and PSR-15 but we think that those
specs have made some bad design decisions and this project is here to provide an
alternative. It is always good to have diversity and evolution will show which
is the better solution. Also we should note the fitting XKDC.

Distinction

PSR-7

The classes are mutable (set* instead of with*), you can change the state
of the object.

There is no ServerRequestInterface and UploadedFileInterface

There is only a single way to access query parameters

getHeader returns a string instead of an array which is the 80% case

Thoughts

Because PSR-7 is immutable PSR-15 must have the fn(req): res signature since
it is not possible to change the response object.

The middleware needs to know how to create a HTTP response instance. Because
of this you can't inject a different response implementation into your
middleware stack. As workaround we see a HTTP factory PSR, but we think this
is a code-smell.

If your app uses a PHP server like Swoole you want to wrap the Swoole response
object and pass it to the middleware to handle also streaming use cases.

Immutability forces a design on your application you have i.e. not the
option to use the double-pass middleware signature.

Since PHP has no immutability on the language level we must
always copy the object and change a specific value which is bad for memory /
performance.

It is really difficult to migrate legacy applications to the
fn(req): res middleware style since most applications today work with a
mutable HTTP object.

PSR-7 is actually not fully immutable since the body is always mutable