https://github.com/istyle-inc/example-hack-strict-api
Example. HHVM/Hack Nazg Framework Response Assert
https://github.com/istyle-inc/example-hack-strict-api
hack hhvm hypermedia-api nazg-framework
Last synced: 5 months ago
JSON representation
Example. HHVM/Hack Nazg Framework Response Assert
- Host: GitHub
- URL: https://github.com/istyle-inc/example-hack-strict-api
- Owner: istyle-inc
- License: mit
- Archived: true
- Created: 2018-03-18T15:52:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-18T05:23:06.000Z (over 7 years ago)
- Last Synced: 2025-03-08T22:35:06.452Z (7 months ago)
- Topics: hack, hhvm, hypermedia-api, nazg-framework
- Language: Hack
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nazg Framework - Response Type Assert Sample
Example). **Hal, Type Assert Middleware, Cors**
## Get Strated
```bash
$ git clone https://github.com/istyle-inc/example-hack-strict-api.git
$ hhvm -d xdebug.enable=0 -d hhvm.jit=0 -d hhvm.php7.all=1\
-d hhvm.hack.lang.auto_typecheck=0 $(which composer) install
```## Example
```bash
$ curl http://example-hack-strict-api.vagrant/
```### Response
```
Content-Type application/hal+json
``````json
{
"id": 1234,
"name": "ytake",
"title": "type-assert for api response",
"_links": {
"self": {
"href": "/",
"type": "application/json"
}
},
"_embedded": {
"enviroments": [
{
"name": "HHVM/Hack",
"_links": {
"self": {
"href": "https://docs.hhvm.com/"
}
}
},
{
"name": "zend-diactoros",
"_links": {
"self": {
"href": "https://zendframework.github.io/zend-diactoros/"
}
}
}
]
}
}
```### Response Type Assert Middleware
```hack
string,
'_links' => shape(
'self' => shape(
'href' => string
)
)
);const type hateoasStructure = shape(
'id' => int,
'name' => string,
'title' => string,
'_links' => shape(
'self' => shape(
'href' => string,
'type' => string
)
),
'_embedded' => shape(
'enviroments' => array
)
);public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler,
): ResponseInterface {
$response = $handler->handle($request);
$decode = json_decode($response->getBody()->getContents(), true);
TypeAssert\matches_type_structure(
type_structure(self::class, 'hateoasStructure'),
$decode,
);
return $response;
}
}```