承接 innmind/rest-bundle 相关项目开发

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

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

innmind/rest-bundle

最新稳定版本:2.0.2

Composer 安装命令:

composer require innmind/rest-bundle

包简介

This Bundle wraps the innmind rest server library

关键字:

README 文档

README

Scrutinizer Code Quality Code Coverage Build Status

SensioLabsInsight

Wrapper for the innmind/rest-server library allowing you to easily expose a REST L3 API.

This bundle offer a complete integration of the library in a symfony project. It also add a new feature called server capabilities; put simply, it expose a route OPTIONS * that will output the list of routes exposed via this bundle. The goal being to allow client discovery, you could imagine a REST client that could prefetch all the resources definitions so it could know in advance if the resources it will try to send match the definitions.

Installation

composer require innmind/rest-bundle

Enable the bundle by adding the following line in your app/AppKernel.php of your project:

// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Innmind\RestBundle\InnmindRestBundle,
        );
        // ...
    }
    // ...
}

Then specify your resources in the configuration under:

innmind_rest:
    server:
        collections: [] #same configuration as the rest server library
        prefix: /api/prefix #optional

Server

Storage

To define a storage you can create a service having either innmind_rest.server.storage.abstract.doctrine or innmind_rest.server.storage.abstract.neo4j as parent. Then you need to specify the first argument to construct the service, being an instance of an entity manager (a doctrine or neo4j one); and flag the service with the tag innmind_rest.server.storage, the bundle will look for the attribute alias on this tag to use as reference afterward (name used to specify storage on your resources).

Formats

As allowed formats are handled via encoders, you declare new ones with a tag on the encoder service you want to add.

Example of the built-in json format:

innmind_rest.server.serializer.encoder.json:
    class: Innmind\Rest\Server\Serializer\Encoder\JsonEncoder
    tags:
        - { name: serializer.encoder }
        - { name: innmind_rest.server.format, format: json, mime: application/json, priority: 10 }

Events

In most cases the only event you'll want to alter will be KernelEvents::RESPONSE or Events::{STORAGE}_READ_QUERY_BUILDER (STORAGE can be DOCTRINE or NEO4J) to add restriction on the query like for example the user being connected.

You can look at Events.php to review all the events you have at your disposition.

Client

To consume an API you need to use the innmind_rest.client service. Examples of usages:

use Innmind\Rest\Client\HttpResource;

$client = $container->get('innmind_rest.client');

$resources = $client->getServer('http://example.com')->read('some_resource');
$resource = $client->getServer('http://example.com')->read('some_resource', 42);

$toCreate = new HttpResource;
$toCreate->set('someProperty', 'value');
$client->getServer('http://example.com')->create('some_resource', $toCreate);

$toUpdate = new HttpResource;
$toUpdate
    ->set('all', 'properties')
    ->set('must', 'be set');
$client->getServer('http://example.com')->update('some_resource', 42, $toUpdate);

$client->getServer('http://example.com')->remove('some_resource', 42);

You can use $server->getResources() to view all the resources exposed by the server API; it will return an associative array with the names as keys and the definitions as values.

innmind/rest-bundle 适用场景与选型建议

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

它主要适用于以下技术方向: 「rest」 「api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 innmind/rest-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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