wimski/laravel-psr-http
最新稳定版本:v3.0.0
Composer 安装命令:
composer require wimski/laravel-psr-http
包简介
PSR HTTP setup for Laravel
README 文档
README
Laravel PSR HTTP
This package provides Laravel bindings to make PSR HTTP requests using discovery.
Install
composer require wimski/laravel-psr-http
Usage example
<?php declare(strict_types=1); namespace App\Console\Commands; use Illuminate\Console\Command; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; class TestCommand extends Command { protected $signature = 'http:test'; protected $description = 'Test the HTTP client'; public function __construct( protected ClientInterface $httpClient, protected RequestFactoryInterface $requestFactory, protected StreamFactoryInterface $streamFactory, ) { parent::__construct(); } public function handle(): void { $stream = $this->streamFactory->createStream(json_encode([ 'title' => 'foo', 'body' => 'bar', 'userId' => 1, ])); $request = $this->requestFactory->createRequest('POST', 'https://jsonplaceholder.typicode.com/posts') ->withHeader('Content-type', 'application/json; charset=UTF-8') ->withBody($stream); try { $response = $this->httpClient->sendRequest($request); dump(json_decode((string) $response->getBody(), true)); } catch (ClientExceptionInterface $exception) { dump($exception->getMessage()); } } }
统计信息
- 总下载量: 30.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-28