ytake/hungrr

HTTP Requesr and Response

Maintainers

Details

github.com/ytake/hungrr

Source

Issues

Installs: 17 253

Dependents: 4

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Language:Hack

0.13.3 2020-07-31 04:46 UTC

This package is auto-updated.

Last update: 2021-03-29 00:37:24 UTC


README

Build Status

ytake/hungrr is a Hack package containing implementations of the Hack HTTP Request and 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

$ composer install ytake/hungrr

Usage

Marshaling an incoming request

use type Ytake\Hungrr\ServerRequestFactory;

$request = ServerRequestFactory::fromGlobals();

Response

Json Response

Constructor Detail

  public function __construct(
    private \HH\Lib\Experimental\IO\WriteHandle $body,
    StatusCode $status = StatusCode::OK,
    dict<string, vec<string>> $headers = dict[],
    protected int $encodingOptions = self::DEFAULT_JSON_FLAGS
  )

Example

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

public function __construct(
  mixed $uri,
  Ytake\Hungrr\StatusCode $status,
  dict<string, vec<string>> $headers
)

$uri, MUST be a string or Facebook\Experimental\Http\Message\UriInterface instance.

Example

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