Revision: Wed, 27 Nov 2024 11:25:20 GMT
v3.13 – outdated
This version of the documentation is outdated. Consider upgrading your project to Spiral Framework 3.14
Edit this page

HTTP — Getting started

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

Installation

To install the extension:

composer require spiral/nyholm-bridge

Activate the component by adding two bootloaders:

php
app/src/Application/Kernel.php
public function defineBootloaders(): array
{
    return [
        // ...
        // Fast PSR-7 implementation
        \Spiral\Nyholm\Bootloader\NyholmBootloader::class,
    
        // HTTP core
        \Spiral\Bootloader\Http\HttpBootloader::class,
    
        // PSR-15 handler      
        \Spiral\Bootloader\Http\RouterBootloader::class,
        // ...
    ];
}

Read more about bootloaders in the Framework — Bootloaders section.

Note
See how to use custom PSR-15 handler here.

Make sure to configure routing.

Configuration

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

php
app/config/http.php
return [
    // default base path
    'basePath'   => '/',
    
    // default headers
    'headers'    => [
        'Content-Type' => 'text/html; charset=UTF-8'
    ],

    // application level middleware
    'middleware' => [
        // middleware class name
    ],
];

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