insideapps/api-proxy

提供基于 symfony http client 的基本 api 代理

1.0.6 2024-04-09 16:06 UTC

This package is auto-updated.

Last update: 2024-09-09 14:57:31 UTC


README

基于 Symfony/HttpClient 5.4 的基本代理

要求

  • php >= 8.1
  • symfony/http-client
  • symfony/cache
  • symfony/dotenv

使用方法

  • 基于 Bearer token
$myApiProxy = ProxyFactory::bearerClient(
            baseUrl: 'https://api.example.es/',
            authUrl: 'https://api.example.es/auth',
            credentialItems: [
                'username' => 'username',
                'password' => 'password'
            ]
        );

$myApiResponse = $myApiProxy->get('endoint/someParam');


  • 要启用 GET 请求的缓存(仅适用于 GET),将第二个可选参数设置为 true
...

$myApiResponse = $myApiProxy->get('endoint/someParam',true,60);


在这个例子中,缓存被设置为 true,并在 60 秒后过期(默认为 3600 秒)