hollisho / http-client by hollisho

http-client
31
0
1
Package Data
Maintainer Username: hollisho
Maintainer Contact: he_wenzhi@126.com (Hollis Ho)
Package Create Date: 2023-08-09
Package Last Update: 2024-11-13
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:06:42
Package Statistics
Total Downloads: 31
Monthly Downloads: 10
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Install

$ composer require hollisho/http-client

TestCase

  1. 执行指定目录所有用例
$ ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml
  1. 执行指定文件
$ ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml --test-suffix RequestTest.php
  1. 执行 RequestTest 用例
$ ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml --filter RequestTest
  1. 执行 RequestTest::test 用例
$ ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml --filter RequestTest::test

Basic Use

$httpClient = new BaseClient('https://www.1024plus.com');
$httpClient->pushMiddleware(new AuthRequest());
$httpClient->httpPost('/category/springboot/');

Use Annotation

/**
 * @author Hollis
 * Interface UserService
 *
 * @BaseUrl(host="https://www.1024plus.com/")
 *
 * @package hollisho\httpclientTests\Service
 */
interface UserService
{
    /**
     * @Headers(headers={
     *     @AuthBasic(username="override", password="override"),
     *     @CustomHeader(name="x-override", body="test")
     * })
     *
     * @Action(
     *     method=@Get,
     *     endpoint=@Endpoint(uri="/api/entry/{id}")
     * )
     */
    public function getUser($id);

    /**
     * @Action(
     *     method=@Post,
     *     endpoint=@Endpoint(uri="/resource"),
     *     body=@Body(json=true, name="body")
     * )
     */
    public function createUser($data);
}


// 生成 FeignClient 实例
$client = FeignClientFactory::create(UserService::class);
echo $client->getUser(1);