承接 uhura2/uhura 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

uhura2/uhura

Composer 安装命令:

composer require uhura2/uhura

包简介

A communications officer for RESTful apis

README 文档

README

A communications officer for RESTful APIs

Uhura is a dead simple RESTful API client for just about anything. No need to set up schemas or configure API endpoints, just tell Uhura what you want and go get it.

$github = new Uhura('https://api.github.com');
$response = $github->users->colindecarlo->repos->get();

Installation

Install Uhura using composer.

$ composer require uhura/uhura

Making Requests

Uhura maps what you ask for in your Demeter chain over to the URL that is used to access the resource you want.

Examples

Send a GET request to http://someapi.com/users

$uhura = new Uhura('http://someapi.com');
$response = $uhura->users->get();

Send a GET request to http://someapi.com/users/1

$uhura = new Uhura('http://someapi.com');
$response = $uhura->users(1)->get();

Send a GET request to http://someapi.com/users/1/blogs/some-blog/comments

$uhura = new Uhura('http://someapi.com');
$response = $uhura->users(1)->blogs('some-blog')->comments->get();

CRUD

CRUD operations are super simple with Uhura and are mapped to the create, get, update and delete methods respectively.

Operation Method Signature
Create create($payload)
Read get()
Update update($payload)
Delete delete()

create(array $payload)

Use Uhura's create method to create resources. The create method accepts an associative array of attributes which are sent to the API in the request body as a x-www-form-urlencoded string.

$uhura = new Uhura('http://someapi.com');
$uhura->users->create(['email' => 'example@example.com']);

get()

Use Uhura's get method to get API resources.

$uhura = new Uhura('http://someapi.com');
$response = $uhura->users->get();

update($payload)

Use Uhura's update method to update a resource. The update method accepts an associative array of attributes which are sent to the API in the request body as a x-www-form-urlencoded string.

$uhura = new Uhura('http://someapi.com');
$uhura->users(1)->update(['name' => 'John Doe']);

delete()

Use Uhura's delete method to delete a resource.

$uhura = new Uhura('http://someapi.com');
$uhura->users(1)->delete();

Authentication

Uhura makes authenticated requests by adding the Authorization header to each request that is made.

Using HTTP Basic Auth

Tell Uhura to use HTTP Basic Auth with the useBasicAuthentication($username, $password) method.

$uhura = new Uhura('https://someapi.com');
$uhura->useBasicAuthentication('someuser', 'somepassword');

$uhura->user->update(['email' => 'example@example.com']);

Explicitly Setting the Authorization Header

You can explicitly set the value of the Authorization header by using Uhura's authenticate($token) method.

$uhura = new Uhura('https://someapi.com');
$uhura->authenticate('Bearer somebearertoken');

$uhura->user->update(['email' => 'example@example.com']);

Working With Responses

By default, Uhura returns PSR7 compliant response objects. Working with them would be as simple as, oh I don't know, a GuzzleHttp\Psr7\Response object.

Response Handlers

You can tell Uhura to pass API responses through a Response Handler to augment the return value of the various request methods. For instance, Uhura ships with a Json Response Handler which consumes the response and returns the decoded JSON response body.

$uhura = new Uhura('https://someapi.com');
$uhura->useResponseHandler(new Uhura\ResponseHandler\Json);

$uhura->users(1)->get();
/*
    [
        'email' => 'example@example.com',
        'name' => 'John Doe'
    ]
*/

Writing Custom Response Handlers

Writing your own custom response handler is super simple. Response Handlers are just simple classes which define a handle($response) method. Whatever is returned from the handle method is what Uhura will return to you.

// XML Response Handler
class XmlHandler
{
    public function handle($response)
    {
        return new SimpleXMLElement($response->getBody()->getContents());
    }
}


$uhura = new Uhura('https://someapi.com');
$uhura->useResponseHandler(new XmlHandler);

echo (string)($uhura->users(1)->get());

/*
    <?xml version='1.0' standalone='yes'?>
    <user>
        <email>example@example.com</email>
        <name>John Doe</name>
    </user>
*/

Author

Colin DeCarlo, colin@thedecarlos.ca

License

Uhura is licensed under the MIT License - see the LICENSE file for details.

uhura2/uhura 适用场景与选型建议

uhura2/uhura 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 uhura2/uhura 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 uhura2/uhura 我们能提供哪些服务?
定制开发 / 二次开发

基于 uhura2/uhura 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-12