netflex/http

Netflex HTTP库

v5.0.2 2023-06-14 10:16 UTC

This package is auto-updated.

Last update: 2024-09-16 16:07:15 UTC


README

Stable version Build status License: MIT Contributors Downloads

[只读] Netflex Http组件的子树分割(见netflex/framework

此库提供了一个独立的Http客户端。

安装

composer require netflex/http

使用

<?php

use Netflex\Http\Client;

$client = new Client();

$post = $client->get('https://jsonplaceholder.typicode.com/posts/1');

echo $post->title;

客户端的默认行为是自动根据内容类型解析内容。

如果内容类型是application/json,它将被解析为一个对象。如果您需要将响应作为关联数组,客户端上的所有http方法都接受一个可选的最后布尔参数,启用此功能。

$post = $client->get('https://jsonplaceholder.typicode.com/posts/1', true);

echo $post['title'];

Laravel服务提供者和外观

如果通过Laravel安装,您可以使用外观。服务提供器将自动注册。

<?php

use Netflex\Http\Facades\Http;

$post = Http::get('https://jsonplaceholder.typicode.com/posts/1');

echo $post->title;

您可以选择使用别名

<?php

use Http;

$post = Http::get('https://jsonplaceholder.typicode.com/posts/1');

echo $post->title;