chagamkamalakar/hypermedia

这是我第一个包

dev-master / 0.1.x-dev 2015-11-14 12:33 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:14:54 UTC


README

本项目的主要目标是提供一个流畅的客户端接口来访问符合 HATEOS的REST服务器API。

安装

通过Composer composer require chagamkamalakar/hypermedia="dev-master@dev"

如何使用

主要部分是HttpClient trait,它包含3个抽象方法

抽象方法 getBaseURL(); 抽象方法 authDetailsUserNameAndPWD(); 抽象方法 possibleURLs($resource);

为了使用这些功能

  1. 必须实现上述3个方法
  2. 你的类必须实现ArrayAccess接口以提供分页支持(无需实现任何方法,所有这些方法都由Pagination trait实现)

抽象方法 getBaseURL();

return the base uri for API Server

抽象方法 authDetailsUserNameAndPWD()

If limit rating is there on API ( for Github the limit is 60 req/hr without any authentication)
provide credentials (user_name & password) respectively in array format ['user_name','password'].

抽象方法 possibleURLs($resource);

see the GitHub example file code there is description is given with an example for Accessing Github api

要了解如何使用,请查看GitHub文件。这是一个访问GitHub数据的示例。

分页支持在ArrayLike访问中

示例代码

$client = new \GuzzleHttp\Client();

$gitHub = new \HyperMedia\GitHub($client);

$user = $gitHub->users('laravel');

$repos = $user->repos();

$repo = $repos[5];

$issues = $repo->issues();

$tags = $repo->tags();

$issue = $issues[0];

echo $issue->title. "\n";

echo $issue->body ."\n";

$issue = $issues[50];

echo $issue->title. "\n";

echo $issue->body ."\n";