cspray/labrador-http

There is no license information available for the latest version (1.0.0-beta4) of this package.

1.0.0-beta4 2019-02-02 20:49 UTC

README

Travis GitHub license GitHub release

A PSR-7 compliant microframework built on top of Labrador and FastRoute. Take advantage of a highly extensible, spec-compliant library and easily integrate with existing PSR-7 Middleware and a multitude of open source libraries.

Install

We recommend you use Composer to install the library.

composer require cspray/labrador-http

Quick Start

The quickest way to get started is to use the Cspray\Labrador\Http\bootstrap() function. This registers error and exception handlers, creates an Auryn\Injector and wires the container for the library's required services.

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Cspray\Labrador\Http\Engine;
use Zend\Diactoros\Response\TextResponse;
use function Cspray\Labrador\Http\bootstrap;

$injector = bootstrap();

$engine = $injector->make(Engine::class);

$engine->get('/', new TextResponse('hello world'));
$engine->get('/closure', function() {
    return new TextResponse('Because of course you can do this');
});

// You'd really want to put this in its own file
class MyController {
    
    public function someMethodThatYouName() {
        return new TextResponse('And, yea, from the controller object too');
    }
    
}

$engine->get('/controller-object', MyController::class . '#someMethodThatYouName');

$engine->run();