Revision: Sat, 27 Apr 2024 17:15:49 GMT
v3.9 – outdated
This version of the documentation is outdated. Consider upgrading your project to Spiral Framework 3.12
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
protected const LOAD = [
    // ...

    // Fast PSR-7 implementation
    \Spiral\Nyholm\Bootloader\NyholmBootloader::class,

    // HTTP core
    \Spiral\Bootloader\Http\HttpBootloader::class,

    // PSR-15 handler      
    \Spiral\Bootloader\Http\RouterBootloader::class,

    // ...
];

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.