2017 © Pedro Peláez
 

library restful

A lightweight PHP Restful Client library

image

aronwu/restful

A lightweight PHP Restful Client library

  • Saturday, July 30, 2016
  • by aronwu
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Restful Client

RestfulClient是最轻量的Restful PHP 客户端库, (*1)

如何导入

include '../src/Restful/Client.php';
include '../src/Restful/Exception.php';

class_alias('\Restful\Client', '\RestfulClient');

composer

{
    "require": {
       "aronwu/restful": "*"
    }
}

配置HostAlias

$hostalias = [
    'order' => 'https://orderapi.xxx.com/v1',
    'product' => 'https://productapi.xxx.com/v1',
];

//设置HostAlias
\RestfulClient::hostalias($hostalias);

//可以随时切换到不同的api
//访问order
\RestfulClient::host('order')->...
//访问商品
\RestfulClient::host('proudct')->...


如何设置Http Basic Authorization

\RestfulClient::auth('username', 'token');

Restful动作

支持 GET, POST, PUT, DELETE,PATCH 五个http mothod, (*2)

Restful请求路径

比如 GET /orders/{order_id}/weixinpay, (*3)

\RestfulClient::host('order')->orders('{order_id}')->weixinpay()->get(
 [
   'order_id' => 123456,
   'limit' => 0

 ]
);

每个//之间资源都可以作为方法名称调用,比如/orders/ 可以调用方法orders, 方法参数也作为访问的路径自动添加。, (*4)

手动设置Restful请求路径

\RestfulClient::host('order')->path('/orders/{order_id}/weixinpay')->get(
 [
   'order_id' => 123456,
   'limit' => 0

 ]
);

调用path方法手动设置请求路径。, (*5)

设置POST、PUT请求数据格式

设置x-www-form-urlencoded和 json格式调用format方法,默认是json格式。, (*6)

\RestfulClient::host('order')->orders()->format->('urlencode')->post(
 [
   'product_id' => 123456,
   'order_count' => 2

 ]
);

The Versions

30/07 2016

dev-master

9999999-dev https://github.com/aronwu/Restful

A lightweight PHP Restful Client library

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

by Aron Wu

api curl rest http restful requests

30/07 2016

0.1.0

0.1.0.0 https://github.com/aronwu/Restful

A lightweight PHP Restful Client library

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

by Aron Wu

api curl rest http restful requests