RESTHack
Basic RESTful api library for Hack
Examples
Basic example
<?hh //strict
require __DIR__.'/vendor/autoload.php';
use RestHack\Api;
use RestHack\HttpMethod;
$api = new Api;
$api->registerEndpoint(
'foo/bar',
function() : string {
return 'Found me';
},
HttpMethod::GET
);
$result = $api->resolve('foo/bar', HttpMethod::GET);
var_dump($result); // 'Found me'
Routing with parameters
<?hh //strict
require __DIR__.'/vendor/autoload.php';
use RestHack\Api;
use RestHack\HttpMethod;
$api = new Api;
$api->registerEndpoint(
'foo/bar/(.+)/(.+)',
function(Map $params) : string {
return $params[0] . ' ' . $params[1];
},
HttpMethod::GET
);
$result = $api->resolve('foo/bar/hello/world', HttpMethod::GET);
var_dump($result); // 'hello world'
TODO
- Automatic header setting
- Automatically convert http method to enum value
- Securty + access control