jumbodroid/httpclient
Composer 安装命令:
composer require jumbodroid/httpclient
包简介
HttpClient is an implementation of HTTP Client for PHP and Laravel
README 文档
README
httpclient is a PHP & Laravel package, designed to help PHP developers build robust modern applications that interact with other applications and APIs in the backend to deliver experiences that users love.
httpclient adopts and adheres to or implements the following PHP Standards Recommendations (PSRs):
Leverage httpclient to build modern interconnected applications for the web.
httpclient saves you the hustle of dealing with the more mundane and lower level APIs needed to create interconnected web applications.
Installation
composer require jumbodroid/httpclient
Usage
PSR-7
PSR-7 describes common interfaces for representing HTTP messages as described in RFC 7230 and RFC 7231, and URIs for use with HTTP messages as described in RFC 3986. This package includes an implementation of PSR-7.
Request | Response
Use the getHeaderLine() method to retrieve a header value as a string containing all header values of a case-insensitive header by name concatenated with a comma.
$response->withHeader('foo', 'bar') ->withAddedHeader('foo', 'baz'); $response->getHeaderLine('foo'); // outputs 'bar,baz'
Use getHeader() to retrieve an array of all the header values for a particular case-insensitive header by name.
$response->getHeader('foo'); // outputs ['bar', 'baz']
Note: Not all header values can be concatenated using a comma (e.g., Set-Cookie). When working with such headers, consumers of Request and Response classes SHOULD rely on the getHeader() method for retrieving such multi-valued headers.
Request
$request->getProtocolVersion(); $request->withProtocolVersion($version); $request->getHeaders(); $request->hasHeader($name); $request->getHeader($name); $request->getHeaderLine($name); $request->withHeader($name, $value); $request->withAddedHeader($name, $value); $request->withoutHeader($name); $request->getBody(); $request->withBody(StreamInterface $body);
Outgoing, client-side request
$request->getRequestTarget(); $request->withRequestTarget($requestTarget); $request->getMethod(); $request->withMethod($method); $request->getUri(); $request->withUri(UriInterface $uri, $preserveHost = false);
Incoming, server-side request
$request->getServerParams(); $request->getCookieParams(); $request->withCookieParams(array $cookies); $request->getQueryParams(); $request->withQueryParams(array $query); $request->getUploadedFiles(); $request->withUploadedFiles(array $uploadedFiles); $request->getParsedBody(); $request->withParsedBody($data); $request->getAttributes(); $request->getAttribute($name, $default = null); $request->withAttribute($name, $value); $request->withoutAttribute($name);
Response
$response->getProtocolVersion(); $response->withProtocolVersion($version); $response->getHeaders(); $response->hasHeader($name); $response->getHeader($name); $response->getHeaderLine($name); $response->withHeader($name, $value); $response->withAddedHeader($name, $value); $response->withoutHeader($name); $response->getBody(); $response->withBody(StreamInterface $body);
Outgoing, server-side response
$response->getStatusCode(); $response->withStatus($code, $reasonPhrase = ''); $response->getReasonPhrase();
Stream
$stream->__toString(); $stream->close(); $stream->detach(); $stream->getSize(); $stream->tell(); $stream->eof(); $stream->isSeekable(); $stream->seek($offset, $whence = SEEK_SET); $stream->rewind(); $stream->isWritable(); $stream->write($string); $stream->isReadable(); $stream->read($length); $stream->getContents(); $stream->getMetadata($key = null);
Uri
$uri->getScheme(); $uri->getAuthority(); $uri->getUserInfo(); $uri->getHost(); $uri->getPort(); $uri->getPath(); $uri->getQuery(); $uri->getFragment(); $uri->withScheme($scheme); $uri->withUserInfo($user, $password = null); $uri->withHost($host); $uri->withPort($port); $uri->withPath($path); $uri->withQuery($query); $uri->withFragment($fragment); $uri->__toString();
UploadedFile
$uploadedFile->getStream(); $uploadedFile->moveTo($targetPath); $uploadedFile->getSize(); $uploadedFile->getError(); $uploadedFile->getClientFilename(); $uploadedFile->getClientMediaType();
PSR-17
PSR-17 describes a common standard for factories that create PSR-7 compliant HTTP objects. This package provides an implementation of PSR-17.
RequestFactory
RequestFactory::createRequest(string $method, $uri);
ResponseFactory
ResponseFactory::createResponse(int $code = 200, string $reasonPhrase = '');
ServerRequestFactory
ServerRequestFactory::createServerRequest(string $method, $uri, array $serverParams = []);
StreamFactory
StreamFactory::createStream(string $content = ''); StreamFactory::createStreamFromFile(string $filename, string $mode = 'r'); StreamFactory::createStreamFromResource($resource);
UploadedFileFactory
UploadedFileFactory::createUploadedFile( StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null );
UriFactory
UriFactory::createUri(string $uri = '');
PSR-18
Client - A Client is a library that implements this specification for the purposes of sending PSR-7-compatible HTTP Request messages and returning a PSR-7-compatible HTTP Response message to a Calling library.
Calling Library - A Calling Library is any code that makes use of a Client. It does not implement this specification's interfaces but consumes an object that implements them (a Client).
Client
$client->sendRequest(RequestInterface $request);
ClientException
RequestException
$requestException->getRequest();
NetworkException
$requestException->getRequest();
jumbodroid/httpclient 适用场景与选型建议
jumbodroid/httpclient 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「http」 「client」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jumbodroid/httpclient 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jumbodroid/httpclient 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jumbodroid/httpclient 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
http客户端
Easily add Excepct-CT header to your project
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
统计信息
- 总下载量: 1.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-18