You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Fast, type-safe request routing, parameter retrieval, and link generation, with PSR-7 support.
Components
HTTP Exceptions
Exception classes representing common situations in HTTP applications:
InternalServerError
MethodNotAllowed
NotFoundException
BaseRouter
A simple typed request router. Example:
<?hh// strict/** TResponder can be whatever you want; in this case, it's a * callable, but classname<MyWebControllerBase> is also a * common choice.*/typeTResponder= (function(ImmMap<string, string>):string);
finalclassBaseRouterExampleextendsBaseRouter<TResponder> {
protectedfunctiongetRoutes(
): ImmMap<HttpMethod, ImmMap<string, TResponder>> {
returnImmMap {
HttpMethod::GET=>ImmMap {
'/'=>
($_params) ==>'Hello, world',
'/user/{user_name}'=>
($params) ==>'Hello, '.$params['user_name'],
},
HttpMethod::POST=>ImmMap {
'/'=> ($_params) ==>'Hello, POST world',
},
};
}
}
The hhvm/hack-router-codegen
project builds on top of of this project to automatically generate:
Full request routing objects and URI maps based on UriPatterns defined in the
controllers
Per-controller parameter classes, allowing $params->getFoo() instead of
$params->getString('Foo'); this allows the typechecker to catch more
errors, and IDE autocomplete functionality to support parameters.
Per-controller UriBuilder classes, with similar benefits
Contributing
We welcome GitHub issues and pull requests - please see CONTRIBUTING.md for details.