vectorface / api-client-php
API 的 PHP 客户端
dev-master
2019-04-08 20:03 UTC
Requires
- php: ^7.0
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is not auto-updated.
Last update: 2024-09-23 15:35:56 UTC
README
基于 cURL 的一个非常简单/直观的 JSON/REST API 客户端。
先决条件
- 必须具有 REST API 的用户名、密码和 URL
- 必须运行 PHP >= 7.0
示例
<?php require_once './vendor/autoload.php'; use VectorFace\Client\API; /* Initialize the API client */ $api = new API([ 'username' => 'example', 'password' => '3x4mpl3', 'url' => 'http://domain.tld' ]); /* * This will: * - Make a request to * http://domain.tld/users?filters=fname:Jon&fields=user_id,fname,lname * - JSON-decode the response * - return the result */ $response = $api->request('/users', [ 'filters' => 'fname:Jon', 'fields' => 'user_id,fname,lname' ]); // $response should contain a decoded JSON response from the API