lukaszterg / restc
简单快捷的 REST 客户端
dev-master
2024-07-02 08:30 UTC
Requires
- php: >=7.0.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- php: >=7.0.0
This package is auto-updated.
Last update: 2024-10-02 10:22:26 UTC
README
https://github.com/lukaszterg/restc (c) 2024 lukaszjarosinski@gmail.com
安装
$ php composer.phar require lukaszterg/restc
基本用法
$client = new Client(); $headers = array("Content-Type" => "application/x-www-form-urlencoded"); //example headers, unnecessary $parameters = array('name'=>'Name','gender'=>'male','email'=>'email@email.com','status'=>'active'); //example parameters, unnecessary $client->get('http://www.boredapi.com/api/activity'); //url echo "<pre>"; var_dump($client->returnResponse()); echo "</pre>";
可配置选项
headers
- 一个包含每个请求中要包含的 HTTP 头部和值的关联数组。
parameters
- 一个包含每个请求中要包含的 URL 或体参数的关联数组。
user_agent
- 用于请求的用户代理字符串。
username
- 用于 HTTP 基本认证的用户名。需要 password
。
password
- 用于 HTTP 基本认证的密码。需要 username
。
支持的方法
该工具支持 GET、POST、PATCH、DELETE 方法。示例
$client->get('http://www.boredapi.com/api/activity'); $client->post('https://gorest.co.in/public/v1/users',array('name'=>'Name','gender'=>'male','email'=>'email@email.com','status'=>'active'),array('Authorization'=>'Bearer '.$token));