{"id":17844305,"url":"https://github.com/usox/sharesta","last_synced_at":"2025-04-02T15:10:50.175Z","repository":{"id":57076254,"uuid":"65139371","full_name":"usox/sharesta","owner":"usox","description":"Sharesta (Strict HAck RESTful Apis) is a micro framework to build simple and easy to use rest-like applications - written in strict hack.","archived":false,"fork":false,"pushed_at":"2020-05-15T06:00:37.000Z","size":98,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T05:44:44.809Z","etag":null,"topics":["api","framework","hack","hacklang","hhvm","hhvm-site","microframework","rest","restful"],"latest_commit_sha":null,"homepage":"","language":"Hack","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/usox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-07T15:07:33.000Z","updated_at":"2022-12-14T18:35:44.000Z","dependencies_parsed_at":"2022-08-24T14:55:50.110Z","dependency_job_id":null,"html_url":"https://github.com/usox/sharesta","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usox%2Fsharesta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usox%2Fsharesta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usox%2Fsharesta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usox%2Fsharesta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usox","download_url":"https://codeload.github.com/usox/sharesta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246837683,"owners_count":20841903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","framework","hack","hacklang","hhvm","hhvm-site","microframework","rest","restful"],"created_at":"2024-10-27T21:28:38.948Z","updated_at":"2025-04-02T15:10:50.155Z","avatar_url":"https://github.com/usox.png","language":"Hack","readme":"# Sharesta - Strict HAck RESTful Apis\n\nA micro framework to build simple and easy to use rest-like apis - written in\nstrict hack ([Hack](http://hacklang.org)).\n\n## Usage\n\nFirst, build some classes containing your logic..\n\n```php\n\nfinal class HomeRoute implements \\JsonSerializable {\n\n    public function jsonSerialize(): string {\n        return 'Welcome home';\n    }\n}\n\nfinal class UpdateUserRoute implements \\JsonSerializable {\n\n    public function __construct(\n        private int $user_id,\n        private \\Usox\\Sharesta\\RequestInterface $request\n    ): void {\n    }\n\n    public function jsonSerialize(): bool {\n        // do some magic, e.g. access the request body by $this-\u003erequest\n        return true;\n    }\n\n}\n```\n\nNow create a class containing your route configurations.\n\n```php\nfinal class Routes implements Usox\\Sharesta\\RoutesInterface {\n\n    public function registerRoutes(Usox\\Sharesta\\RouterInterface $router): void {\n        $router-\u003eget(\n            '/',\n            (Usox\\Sharesta\\RequestInterface $request): \\JsonSerializable ==\u003e {\n                return new HomeRoute();\n            }\n        );\n\n        /**\n         * Get variables from the path (e.g. `http://some.tld/users/123`)\n         */\n        $router-\u003epost(\n            '/users/:id',\n            (Usox\\Sharesta\\RequestInterface $request): \\JsonSerializable ==\u003e {\n                return new UpdateUserRoute(\n                    $request-\u003egetUriValues('id'),\n                    $request-\u003egetRequestBody()\n                );\n            }\n        );\n    }\n}\n```\n\nSetup sharesta, register your routes and let the application controller handle your requests.\n\n```php\n\u003c?hh // strict\n\nrequire_once 'vendor/autoload.php';\n\n\u003c\u003c__Entrypoint\u003e\u003e\nfunction main(): noreturn {\n\t/* HH_IGNORE_ERROR[2050] */ $get_vars = dict($_GET);\n\t/* HH_IGNORE_ERROR[2050] */ $server_vars = dict($_SERVER);\n\n    $factory = new Usox\\Sharesta\\ApiFactory();\n    $router = $factory-\u003ecreateRouter(\n        $server_vars,\n        $get_vars\n    );\n\n    $routes = new Routes();\n    $routes-\u003eregisterRoutes($router);\n\n    $router-\u003eroute(\n        '' // path to the file. Leave it empty if your server configuration defaults to index.hh\n    );\n\n    die(0);\n}\n```\n\n## Example\n\nSee `example/webroot/index.hh` for an example.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusox%2Fsharesta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusox%2Fsharesta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusox%2Fsharesta/lists"}