fp-web
, (*1)
Test bed for a functional web toolkit, (*2)
This is just an experiment for what a web toolkit that doesn't use
object-oriented code., (*3)
In theory, this is just a bit of PHP and should be fine for use, but in
practice, don't use this but use something more established, more tested, and
more used instead., (*4)
Running the example
$ git clone https://github.com/slogsdon/php-fp-web
$ cd php-fp-web
$ composer install
$ php -S 0.0.0.0:8888 -t example
In another terminal session:, (*5)
$ curl -i http://localhost:8800/index
HTTP/1.1 200 OK
Host: localhost:8888
Connection: close
X-Powered-By: PHP/5.6.10
Content-type: text/html; charset=UTF-8
index
$ curl -i http://localhost:8800/
HTTP/1.1 404 Not Found
Host: localhost:8888
Connection: close
X-Powered-By: PHP/5.6.10
Content-type: text/html; charset=UTF-8
Not Found
Usage
<?php
require 'vendor/autoload.php';
use \FPWeb\App;
use \FPWeb\Route;
// index handler
$index = function ($conn) {
// TODO: make this process nicer
$conn['response']['body'] = 'index';
return $conn;
};
// create routes
$routes = [
Route\get('/index', $index),
];
// match request and run match
$response = App\run($routes, [
'param_set' => [$_GET, $_POST],
'on_error' => function ($conn) {
$conn['response']['body'] = 'Not Found';
return $conn;
},
]);
printf('
%s
', print_r($response, true));