Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Feb 21, 2025. It is now read-only.
/sharestaPublic archive

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

Repository files navigation

A micro framework to build simple and easy to use rest-like apis - written instrict hack (Hack).

Usage

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);}

Example

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

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp