定制 jmeyering/hal-explorer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

jmeyering/hal-explorer

Composer 安装命令:

composer require jmeyering/hal-explorer

包简介

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

README 文档

README

Build Status Code Climate

HalExplorer is a php client useful for exploring HAL formatted apis. HalExplorer is able to craft requests and follow links to retreive, create, update and delete resource relationships.

The codebase is fully covered by phpspec and extensively documented.

Install

composer require jmeyering/hal-explorer

##Docs

readthedocs

Api Documentation

To generate api documentation use whatever phpdoc generation tool you want but apigen is included with the composer deps. Just run vendor/bin/apigen generate to create the documentation, then point your browser to public/index.html to view.

PSR7

The library makes exclusive use of PSR7 messages. Whatever http client is used internally must return PSR7 Message interfaces.

Usage

To use the exploration feature of the library we need to think about our responses and their included _links as objects and relationships.

Fetching, Creating, Updating, and Deleting are the primary actions to perform on a related object. HalExplorer exposes this functionality with the getRelation, createRelation, updateRelation, patchUpdateRelation and deleteRelation methods.

As expected, these methods map to the GET, POST, PUT, PATCH and DELETE HTTP verbs.

$explorer->createRelation($object, "association");

Example

We will use the haltalk api as an endpoint example and guzzlehttp/guzzle for our HTTP Client.

// This Example creates a new account with haltalk and creates a post from that
// account.
$client = new \GuzzleHttp\Client();
$explorer = new \HalExplorer\Explorer();
$adapter = new \HalExplorer\ClientAdapters\Adapter();

$adapter->setClient($client);
$explorer->setAdapter($adapter)->setBaseUrl("http://haltalk.herokuapp.com");

// The haltalk api requires both "application/hal+json" and, application/json"
// Accept headers to work. hal-explorer only adds "application/hal+json" by
// default so we need to override this default value.
$explorer->setDefaults(function($original){
    $original["headers"]["Accept"] = "application/hal+json, application/json";

    return $original;
});

$username = "myuniqueusername";

// Enter the haltalk api and return a PSR7 ResponseInterface
$entrypoint = $explorer->enter();

// Create an account with haltalk.
$accountResponse = $explorer->createRelation($entrypoint, "signup", [
    "body" => '{
        "username": "'.$username.'",
        "password": "password"
    }'
]);

// Retreive my account information using thy "me" link on the entrypoint.
// Because this is a templated link, we must pass templated data along.
$myAccount = $explorer->getRelation($entrypoint, "me", [
    "template" => [
        "name" => $username,
    ],
]);

// Create a post from my account. This resource requires basic auth.
$post = $explorer->createRelation($myAccount, "posts", [
    "body" => '{
        "content": "This is my post Content"
    }',
    "auth" => [
        $username,
        "password"
    ]
]);

// Haltalk return the post location in a response header. We can fetch that
// information using the PSR7 method, getHeaderLine()
$postLocation = $post->getHeaderLine("location");

jmeyering/hal-explorer 适用场景与选型建议

jmeyering/hal-explorer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.51k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2015 年 08 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 jmeyering/hal-explorer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 21.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-04