Skip to content

ch00_installation

Daniel Samson edited this page Oct 15, 2019 · 15 revisions

Get teensyphp

composer require daniel-samson/teensyphp

Create index.php

<?php
require_once __DIR__ . '/vendor/autoload.php';
display_errors(false);
error_reporting(E_ALL);

try {
    // home / landing page
    route(method(GET), url_path("/"), function () {
        render(200, json_out(['hello' => 'world']));
    });

    // route not found
    render(404, json_out(['error' => 'not found']));
} catch (Exception $e) {
    error_log($e->getMessage());
    error_log($e->getTraceAsString());
    render($e->getCode(), json_out(['error' => 'internal server error']));
} catch (Error $e) {
    error_log($e->getMessage());
    error_log($e->getTraceAsString());
    render($e->getCode(), json_out(['error' => 'internal server error'])));
}
Clone this wiki locally