openclerk/apis 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

openclerk/apis

最新稳定版本:0.1.0

Composer 安装命令:

composer require openclerk/apis

包简介

A library for defining and using APIs

README 文档

README

A library for defining APIs in Openclerk, live on CryptFolio.

Installing

Include openclerk/apis as a requirement in your project composer.json, and run composer update to install it into your project:

{
  "require": {
    "openclerk/apis": "dev-master"
  }
}

Using

Define subclasses of \Apis\Api to define endpoints and content:

/**
 * API to get a single currency properties.
 */
class Currency extends \Apis\Api {

  function getJSON($arguments) {
    $cur = \DiscoveredComponents\Currencies::getInstance($arguments['currency']);
    $result = array(
      'code' => $cur->getCode(),
      'title' => $cur->getName(),
    );

    return $result;
  }

  function getEndpoint() {
    return "/api/v1/currency/:currency";
  }

}

You can then call $api->render() for the specific API.

Using with magic

Your APIs can be discovered with component-discovery by defining apis.json:

{
  "api/v1/currencies": "\\Core\\Api\\Currencies",
  "api/v1/currency/:currency": "\\Core\\Api\\Currency"
}

You can then load these into openclerk/routing at runtime:

// load up API routes
foreach (DiscoveredComponents\Apis::getAllInstances() as $uri => $handler) {
  \Openclerk\Router::addRoutes(array(
    $uri => $handler,
  ));
}

Caching

Using openclerk/cache you can also cache API calls:

/**
 * API to get a single currency properties.
 */
class Currency extends \Apis\CachedApi {

  // ...

  function getHash($arguments) {
    return substr($arguments['currency'], 0, 32);
  }

  function getAge() {
    return 60; /* cache age in seconds */
  }
}

TODO

  1. Documentation on Apis\Fetch methods
  2. A way to define APIs lazily without instantiating all Apis at every request time
  3. Tests

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-12-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固