Skip to content

Route Response

Joshua Parker edited this page Dec 23, 2020 · 2 revisions

Qubus Router supports the following responses.

use Qubus\Http\Factories\EmptyResponseFactory;
use Qubus\Http\Factories\HtmlResponseFactory;
use Qubus\Http\Factories\JsonResponseFactory;
use Qubus\Http\Factories\TextResponseFactory;
use Qubus\Http\Factories\XmlResponseFactory;

$router->get('/empty', function () {
    return EmptyResponseFactory::create();
});

$router->get('/html/1', function () {
    return '<html>This is an HTML response.</html>';
});

$router->get('/html/2', function () {
    return HtmlResponseFactory::create(
        '<html>This is another HTML response.</html>',
        200,
        ['Content-Type' => ['application/xhtml+xml']]
    );
});

$router->get('/json', function () {
    return JsonResponseFactory::create(
        'This is a JSON response.',
        200,
        ['Content-Type' => ['application/hal+json']]
    );
});

$router->get('/text', function () {
    return TextResponseFactory::create(
        'This is a text response.',
        200,
        ['Content-Type' => ['text/csv']]
    );
});

$router->get('/xml', function () {
    return XmlResponseFactory::create(
        'This is an xml response.',
        200,
        ['Content-Type' => ['application/hal+xml']]
    );
});
Clone this wiki locally