Routing

The purpose of websites is to respond to requests (home page, subpage, assets) and routing in Bear Framework makes this very easy. When you create your app, you can describe different request handlers for different request types. Here is how you can register a callback function that will be called if there is a match with the request parameters. The response object (BearFramework\App\Response) returned by the callback will be sent to the client.

Different method and protocol checks

// Will match POST http://example.com/
$app->routes->add('/', function() {
    return new App\Response\JSON(json_encode(['result' => 'ok']));
}, ['POST']);

// Will match GET https://example.com/
$app->routes->add('/', function() {
    return new App\Response\HTML('Hi');
}, ['GET', 'HTTPS']);

// Will match GET|HEAD https://example.com/
$app->routes->add('/', function() {
    return new App\Response\HTML('Hi');
}, ['GET', 'HEAD', 'HTTPS']);
Next: Data