This repository was archived by the owner on Feb 21, 2025. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork1
Sharesta (Strict HAck RESTful Apis) is a micro framework to build simple and easy to use rest-like applications - written in strict hack.
License
NotificationsYou must be signed in to change notification settings
usox/sharesta
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A micro framework to build simple and easy to use rest-like apis - written instrict hack (Hack).
First, build some classes containing your logic..
finalclass HomeRouteimplements \JsonSerializable {publicfunctionjsonSerialize():string {return'Welcome home'; }}finalclass UpdateUserRouteimplements \JsonSerializable {publicfunction__construct(privateint$user_id,private\Usox\Sharesta\RequestInterface$request ):void { }publicfunctionjsonSerialize():bool {// do some magic, e.g. access the request body by $this->requestreturntrue; }}
Now create a class containing your route configurations.
finalclass RoutesimplementsUsox\Sharesta\RoutesInterface {publicfunctionregisterRoutes(Usox\Sharesta\RouterInterface$router):void {$router->get('/', (Usox\Sharesta\RequestInterface$request): \JsonSerializable ==> {returnnewHomeRoute(); } );/** * Get variables from the path (e.g. `http://some.tld/users/123`) */$router->post( '/users/:id', (Usox\Sharesta\RequestInterface$request): \JsonSerializable ==> {returnnew UpdateUserRoute($request->getUriValues('id'),$request->getRequestBody() ); } ); }}
Setup sharesta, register your routes and let the application controller handle your requests.
<?hh// strictrequire_once'vendor/autoload.php';<<__Entrypoint>>function main(): noreturn {/* HH_IGNORE_ERROR[2050] */$get_vars =dict($_GET);/* HH_IGNORE_ERROR[2050] */$server_vars =dict($_SERVER);$factory =newUsox\Sharesta\ApiFactory();$router =$factory->createRouter($server_vars,$get_vars );$routes =newRoutes();$routes->registerRoutes($router);$router->route(''// path to the file. Leave it empty if your server configuration defaults to index.hh );die(0);}
Seeexample/webroot/index.hh
for an example.
About
Sharesta (Strict HAck RESTful Apis) is a micro framework to build simple and easy to use rest-like applications - written in strict hack.
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published