Revision: Fri, 17 May 2024 13:03:36 GMT
v2.14 – outdated
This version of the documentation is outdated. Consider upgrading your project to Spiral Framework 3.12
Edit this page

HTTP - Installation and Configuration

The web application bundle (spiral/app) ships with a pre-configured HTTP component. You will need several extensions to enable it in alternative builds.


To install the extension:

composer require spiral/nyholm-bridge

Activate the extension by adding two bootloaders:

class App extends Kernel
     * List of components and extensions to be automatically registered
     * within system container on application start.
    protected const LOAD = [
        // ...

        // Fast PSR-7 implementation

        // HTTP core

        // PSR-15 handler      

        // ...

See how to use custom PSR-15 handler here.

Make sure to configure routing.


The HTTP extension can be configured via app/config/http.php file:

return [
    // default base path
    'basePath'   => '/',
    // default headers
    'headers'    => [
        'Content-Type' => 'text/html; charset=UTF-8'

    // application level middleware
    'middleware' => [
        // middleware class name

The default configuration will be used if such file does not exist.

You can register Middleware during the bootload phase via HttpBootloader:

namespace App\Bootloader;

use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Bootloader\Http\HttpBootloader;
use Spiral\Http\Middleware\JsonPayloadMiddleware;

class AppBootloader extends Bootloader
    public function boot(HttpBootloader $http): void
        // parse json payloads


HTTP extension includes multiple middlewares you might want to activate in your project:

Bootloader Middleware
Spiral\Bootloader\Http\ErrorHandlerBootloader Hide exceptions in non debug mode and render HTTP error pages.
Spiral\Bootloader\Http\JsonPayloadsBootloader Parse body of application/json requests.
Spiral\Bootloader\Http\PaginationBootloader Use request query parameters to automatically configure paginator(s).
Spiral\Bootloader\Http\DiactorosBootloader Use Zend/Diactoros as PSR-7 implementation (legacy).