nddcoder/laravel-http-client

laravel 的 Guzzle 封装

v1.2.0 2019-04-18 14:10 UTC

This package is auto-updated.

Last update: 2024-09-19 02:36:33 UTC


README

安装

您可以通过 composer 安装此包

composer require nddcoder/laravel-http-client

用法

将 HttpClient 注入到控制器构造函数中

use Nddcoder\HttpClient\HttpClient;

class TodoController extends Controller 
{
    private $http;

    public function __construct(HttpClient $http)
    {
        $this->http = $http;
    }

    public function index()
    {
        return $this->http->get('https://jsonplaceholder.typicode.com/todos');
        
        /*
            {
                "status_code": 200,
                "headers": {},
                "body": "...",
                "bodyJSON": [...]
            }
        */
    }
}

许可协议

MIT 许可协议 (MIT)。请参阅许可文件获取更多信息。