philwaters / api
API router
0.4.0
2017-09-14 19:36 UTC
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2025-04-27 06:13:03 UTC
README
API router
Example
$router = new PhilWaters\API\Router();
$router ->url("people/(?P[0-9]+).(?P(json|text))") ->method("GET") ->handler(array("PeopleController", "load"));
$router->run($_GET['url'], $_SERVER['REQUEST_METHOD'], $_REQUEST);
use PhilWaters\API\BaseController;
class PeopleController extends PhilWaters\API\BaseController { public function load($id, $format) { $data = array();
if ($format == "json") {
$this->respondJSON($data);
} else {
$this->respondText(implode(",", $data));
}
}
}
GET /api/people/7.json HTTP/1.1