Teensy PHP is a micro web framework for rapidly creating REST APIs and hypermedia.
- Lightweight Framework
- Simple Router
- PHP Templating Engine
- Middleware Support
- Easy to inject or replace functionality (its just some small functions)
// index.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
router(function() {
// uncomment when using laravel valet/herd or when mod_rewrite is unavailable:
// use_request_uri();
//
// healthcheck
route(method(GET), url_path("/"), fn () => render(200, json_out(['status' => 'up'])));
// Example url parameter
route(method(GET), url_path_params("/hello/:name"), function () {
render(200, html_out(template('src/templates/hello.php', ['name' => $_GET[':name']])));
});
// Example JSON body (echo server)
route(method(POST), url_path("/echo"), function () {
$body = json_in();
render(201, json_out($body));
});
});
- PHP 7.2+
- Composer
Please see the wiki for more information on how to rapidly create apps with teensyphp.