/
endpoint.php
48 lines (44 loc) · 1.08 KB
/
endpoint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* This file is part of the Wrr package.
*
* (c) Jason Woys <jason@woys.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Wrr\Router;
use Wrr\Route\HttpRoute;
use Wrr\Response\HttpResponse;
require_once __DIR__ . '/../../vendor/autoload.php';
/*
* make a wildcard route that covers everything and will result in a sane default
*/
$router = new Router();
$router->registerRoute(
new HttpRoute(
'^/',
function () {
return "Wrr!... You've been served! ";
}
)
); // catch all
$defaultResponse = new HttpResponse();
$router->registerHttpRoute(
'wrr',
'GET',
function () {
return ["Wrr status", "Wrr is Cool!"];
}
);
try {
$headers = ['X-Meta: Response Built by Wrr!'];
$response = $router
->respond(200, $headers);
} catch (Exception $e) {
$response = new \Wrr\Response\HttpResponse();
$response
->setPayload($e->getMessage())
->setResponseCode($e->getCode() ?: 500)
->deliverPayload();
}