Http version of the weew/app package.



Http App

Build Status Code Quality Test Coverage Version Licence

Table of contents


composer require weew/http-app


This is a very minimalistic wrapper for a http application.


The whole app lifecycle is event based. To successfully handle http requests you must handle the HandleHttpRequestEvent and provide a valid response that implements the IHttpResponse interface.

Below is a very basic example of how you might implement this.

$app = new HttpApp();
    ->subscribe(HandleHttpRequestEvent::class, function(HandleHttpRequestEvent $event) {
        $request = $event->getRequest();

        // handle request (do some routing, call a controller, etc.)
        // provide a response that implements the IHttpResponse interface

There is already an existing implementation for this, see weew/http-app-request-handler.

Environment awareness

Sometimes you might want, for example during tests, to send a request to the same front controller but in a different environment. Symfony does this using different front controllers: app.php and app_dev.php. This approach will however alter the url and might not be suitable in some situations. Beside creating different front controllers you can also specify an environment using the x-env: dev header or a query param ?env=dev or a somewhere inside your url /env=dev/some/url. If an environment setting can be detected either via headers or url query or url part, the corresponding data (x-env header, env query param, env value inside the url) will be automatically removed. This feature is disabled by default and you can enable it by setting debug to true.

 $request = new HttpRequest();

 $request->getHeaders()->set('x-env', 'stage');
 // or
 $request->getUrl()->getQuery()->set('env', 'stage');
 // or

 // app will run in the "stage" environment

You must not use this in production! This is why it is disabled by default. Only enable this feature for your dev environment.


There are several extensions available: