定制 fuziion/http-api-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fuziion/http-api-client

Composer 安装命令:

composer require fuziion/http-api-client

包简介

This PHP library provides a simple and versatile HTTP API client for interacting with APIs. It allows you to make GET and POST requests to an API, and it also includes a data handling feature for easily working with API response data.

README 文档

README

This PHP library provides a simple and versatile HTTP API client for interacting with APIs. It allows you to make GET and POST requests to an API, and it also includes a data handling feature for easily working with API response data.

Installation

You can install this library using Composer:

composer require fuziion/http-api-client

Usage

To use the Fuziion\HttpApi\Client class, follow these steps:

Import the necessary namespace:

use Fuziion\HttpApi\Client;

Create a Client instance by providing your API key and API URL:

$client = new Client('your-api-key', 'https://api.example.com');

Make GET or POST requests to the API:

GET Request:

$response = $client->get('/some/endpoint');
if ($response) {
    // Access API response data using magic getters
    echo $response->some_key; // Access 'some_key' in the response data
    // Or get the entire data array
    $data = $response->getData();
    print_r($data);
} else {
    // Handle the error
    echo "Error making the API GET request.";
}

POST Request:

$data = [
    'key1' => 'value1',
    'key2' => 'value2',
];

$response = $client->post('/some/endpoint', $data);
if ($response) {
    // Access API response data using magic getters
    echo $response->some_key;
    // Or get the entire data array
    $data = $response->getData();
    print_r($data);
} else {
    // Handle the error
    echo "Error making the API POST request.";
}

Replace 'your-api-key' and 'https://api.example.com' with your actual API key and URL. If the API you are trying to reach does not require an bearer token then just leave this field empty.

DataObject

The library includes a DataObject class for handling API response data with magic getters. It simplifies the process of accessing data within the API response.

use Fuziion\HttpApi\Data\DataObject;

$data = new DataObject(['key1' => 'value1', 'key2' => 'value2']);
echo $data->key1; // Access 'key1' in the data object

License

This library is licensed under the MIT License. See the LICENSE file for details.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2023-10-12