{"id":20631361,"url":"https://github.com/istyle-inc/example-hack-strict-api","last_synced_at":"2025-05-10T06:30:52.803Z","repository":{"id":132796353,"uuid":"125741596","full_name":"istyle-inc/example-hack-strict-api","owner":"istyle-inc","description":"Example. HHVM/Hack Nazg Framework Response Assert","archived":true,"fork":false,"pushed_at":"2018-04-18T05:23:06.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-08T22:35:06.452Z","etag":null,"topics":["hack","hhvm","hypermedia-api","nazg-framework"],"latest_commit_sha":null,"homepage":null,"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/istyle-inc.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-18T15:52:03.000Z","updated_at":"2024-01-23T04:24:36.000Z","dependencies_parsed_at":"2023-06-14T04:33:04.709Z","dependency_job_id":null,"html_url":"https://github.com/istyle-inc/example-hack-strict-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/istyle-inc%2Fexample-hack-strict-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/istyle-inc%2Fexample-hack-strict-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/istyle-inc%2Fexample-hack-strict-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/istyle-inc%2Fexample-hack-strict-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/istyle-inc","download_url":"https://codeload.github.com/istyle-inc/example-hack-strict-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253376552,"owners_count":21898929,"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":["hack","hhvm","hypermedia-api","nazg-framework"],"created_at":"2024-11-16T14:12:02.065Z","updated_at":"2025-05-10T06:30:52.797Z","avatar_url":"https://github.com/istyle-inc.png","language":"Hack","readme":"# Nazg Framework - Response Type Assert Sample\n\nExample). **Hal, Type Assert Middleware, Cors**\n\n## Get Strated\n\n```bash\n$ git clone https://github.com/istyle-inc/example-hack-strict-api.git\n$ hhvm -d xdebug.enable=0 -d hhvm.jit=0 -d hhvm.php7.all=1\\\n -d hhvm.hack.lang.auto_typecheck=0 $(which composer) install\n```\n\n## Example\n\n```bash\n$ curl http://example-hack-strict-api.vagrant/\n```\n\n### Response\n\n```\nContent-Type application/hal+json\n```\n\n```json\n{\n  \"id\": 1234,\n  \"name\": \"ytake\",\n  \"title\": \"type-assert for api response\",\n  \"_links\": {\n    \"self\": {\n      \"href\": \"/\",\n      \"type\": \"application/json\"\n    }\n  },\n  \"_embedded\": {\n    \"enviroments\": [\n      {\n        \"name\": \"HHVM/Hack\",\n        \"_links\": {\n          \"self\": {\n            \"href\": \"https://docs.hhvm.com/\"\n          }\n        }\n      },\n      {\n        \"name\": \"zend-diactoros\",\n        \"_links\": {\n          \"self\": {\n            \"href\": \"https://zendframework.github.io/zend-diactoros/\"\n          }\n        }\n      }\n    ]\n  }\n}\n```\n\n### Response Type Assert Middleware\n\n```hack\n\u003c?hh // strict\n\nnamespace App\\Middleware;\n\nuse Facebook\\TypeAssert;\nuse Psr\\Http\\Message\\ResponseInterface;\nuse Psr\\Http\\Message\\ServerRequestInterface;\nuse Psr\\Http\\Server\\MiddlewareInterface;\nuse Psr\\Http\\Server\\RequestHandlerInterface;\n\nclass ResponseAssertMiddleware implements MiddlewareInterface {\n  \n  const type embeddedLinks = shape(\n    'name' =\u003e string,\n    '_links' =\u003e shape(\n      'self' =\u003e shape(\n        'href' =\u003e string\n      )\n    )\n  );\n\n  const type hateoasStructure = shape(\n    'id' =\u003e int,\n    'name' =\u003e string,\n    'title' =\u003e string,\n    '_links' =\u003e shape(\n      'self' =\u003e shape(\n        'href' =\u003e string,\n        'type' =\u003e string\n      )\n    ),\n    '_embedded' =\u003e shape(\n      'enviroments' =\u003e array\u003cself::embeddedLinks\u003e\n    )\n  );\n\n  public function process(\n    ServerRequestInterface $request,\n    RequestHandlerInterface $handler,\n  ): ResponseInterface {\n    $response = $handler-\u003ehandle($request);\n    $decode = json_decode($response-\u003egetBody()-\u003egetContents(), true);\n    TypeAssert\\matches_type_structure(\n      type_structure(self::class, 'hateoasStructure'),\n      $decode,\n    );\n    return $response;\n  }\n}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fistyle-inc%2Fexample-hack-strict-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fistyle-inc%2Fexample-hack-strict-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fistyle-inc%2Fexample-hack-strict-api/lists"}