ytake/hungrr

HTTP 请求和响应

维护者

详细信息

github.com/ytake/hungrr

源代码

问题

支持包维护!
ytake

安装数: 17,257

依赖项: 4

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

语言:Hack

0.13.3 2020-07-31 04:46 UTC

This package is auto-updated.

Last update: 2024-08-29 04:54:33 UTC


README

Build Status

ytake/hungrr 是一个 Hack 包,包含了对 Hack HTTP 请求和响应接口 的实现

PSR-7 是为 PHP 设计的,不是为 Hack,因此一些决策与 Hack 的类型系统不太兼容。

不支持 PHP

要求

HHVM 4.20.0 及以上版本。

安装

通过 Composer

$ composer install ytake/hungrr

使用

序列化传入请求

use type Ytake\Hungrr\ServerRequestFactory;

$request = ServerRequestFactory::fromGlobals();

响应

JSON 响应

构造函数详情

  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
  )

示例

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

重定向响应

构造函数详情

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

$uri,必须是字符串或 Facebook\Experimental\Http\Message\UriInterface 实例。

示例

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