Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ytake/hungrr
HTTP Message implementation HHVM/Hack
https://github.com/ytake/hungrr
hacklang hhvm http message psr-7 request response
Last synced: about 1 month ago
JSON representation
HTTP Message implementation HHVM/Hack
- Host: GitHub
- URL: https://github.com/ytake/hungrr
- Owner: ytake
- License: mit
- Created: 2018-11-05T10:43:08.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-31T04:53:22.000Z (over 4 years ago)
- Last Synced: 2024-10-05T22:03:03.753Z (4 months ago)
- Topics: hacklang, hhvm, http, message, psr-7, request, response
- Language: Hack
- Homepage:
- Size: 136 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hungrr / HTTP Message implementation
[![Build Status](https://travis-ci.org/ytake/hungrr.svg?branch=master)](https://travis-ci.org/ytake/hungrr)
`ytake/hungrr` is a Hack package containing implementations of the
[Hack HTTP Request and Response Interfaces](https://github.com/hhvm/hack-http-request-response-interfaces)PSR-7 was designed for PHP, not Hack, and some descisions do not fit smoothly with Hack's type system.
Not Supported PHP
## Requirements
HHVM 4.20.0 and above.## Install
via Composer
```bash
$ composer install ytake/hungrr
```## Usage
## Marshaling an incoming request
```hack
use type Ytake\Hungrr\ServerRequestFactory;$request = ServerRequestFactory::fromGlobals();
```## Response
### Json Response
Constructor Detail
```hack
public function __construct(
private \HH\Lib\Experimental\IO\WriteHandle $body,
StatusCode $status = StatusCode::OK,
dict> $headers = dict[],
protected int $encodingOptions = self::DEFAULT_JSON_FLAGS
)
```Example
```hack
use type Ytake\Hungrr\Uri;
use type Ytake\Hungrr\StatusCode;
use type Ytake\Hungrr\Response\RedirectResponse;
use namespace HH\Lib\Experimental\IO;list($read, $write) = IO\pipe_non_disposable();
await $write->writeAsync(\json_encode(dict[
'testing' => dict[
'HHVM' => 'Hack'
]
])));
```### Redirect Response
Constructor Detail
```text
public function __construct(
mixed $uri,
Ytake\Hungrr\StatusCode $status,
dict> $headers
)
```$uri, MUST be a string or Facebook\Experimental\Http\Message\UriInterface instance.
Example
```hack
use type Ytake\Hungrr\Uri;
use type Ytake\Hungrr\StatusCode;
use type Ytake\Hungrr\Response\RedirectResponse;// use uri string
$r = new RedirectResponse('/foo/bar');// use uri instance
$r = new RedirectResponse(new Uri('https://example.com:10082/foo/bar'));
```