承接 kmfk/hateoas-bundle 相关项目开发

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

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

kmfk/hateoas-bundle

Composer 安装命令:

composer require kmfk/hateoas-bundle

包简介

Symfony2 Bundle to add Hateoas compliant urls to JMS Serializer

README 文档

README

While this works as a simple, drop in bundle for Symfony, you can find a much more full featured library and bundle here:

###Overview

The Hateoas Bundle works with JMS Serializer to allow you to easily add Hateoas compliant resource urls to the JSON output of your REST Api.

There are other similar bundles, but they seemed heavy for my needs. This bundle was designed to work seamlessly with JMS Serializer, with out needing to abstract or obfuscate the serialization of your data.

Currently this bundle only provides Annotations for Resource Linking in your Serialized response.

###Hateoas Bundle Installation

The best method of installation is through the use of composer.

#####Add the bundle to Composer

"require": {
    "kmfk/hateoas-bundle": "~0.1",
}

#####Update AppKernel.php

Add The Hateoas Bundle to your kernel bootstrap sequence

public function registerBundles()
{
	$bundles = array(
    	// ...
    	new Kmfk\Bundle\HateoasBundle\HateoasBundle(),
    );

    return $bundles;
}

####Configure the Bundle

The bundle allows you to configure the Rest API host and an optional Path prefix. Your links will be built using these values. If they are not set, the bundle will default to parsing this from the current request.

#app/config.yml

hateoas:
	host:   http://api.example.com/
	prefix: /api/

###Annotations

Once configured, you can use the Annotations provided by this bundle to easily add resource links to your classes and properties.

#src/AcmeBundle/Entity/UserEntity.php

use Kmfk/Bundle/HateoasBundle/Annotation/Hateoas;

/**
 * @Hateoas(
 *      name    ="self",
 *      href    ="/user/{id}/"
 *      params  ={"id" = "getId"},
 *      groups  ={"list"},
 *      type    ="absolute"
 *  )
 */
class UserEntity
{
    protected $id;

    public function getId()
    {
        return $this->id;
    }
}

####Output:

{
    "_links": {
        "self": {
            "href": "http://api.example.com/api/user/1/"
        }
    }
}

###Annotation Reference

Property Description Example
name The property name inside the 'links' attribute user
href The relative (path) url of the resource, including url tokens /user/{id}/
params An associative array of token names with their corresponding getter methods { "id" = "getId" }
groups Serializer Groups, Used the same way as JMS Serializer Groups { "partial", "full" }
type 'Absolute' or 'Embedded' absolute

####Using Params You can have multiple tokens in the href. The params array should be an associative array with keys matching the tokens in the path. Methods listed should be methods that exist in the annotated class.

####Groups Specifying groups allow you to control the output of the links based on Exclusion Groups

####Embedded vs Absolute Links While absolute (default value), will allows include the API Host and optional prefix, embedded urls live beneath another resource. Setting type to 'embedded will allow you to have links like:

{
    "_links": {
        "self": {
            "href": "http://api.example.com/api/user/1/email/1/"
        }
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固