arfaram/ezrestdemobundle

扩展 eZPlatform API 示例

安装: 28

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 1

开放问题: 0

类型:application

v1.1.2 2017-12-17 17:43 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:43:06 UTC


README

扩展 Ez Rest API - 示例

需求

eZPlatform 1.7 + , symfony 2.8 +

用例 - 示例

查看以下演示,以更好地了解如何扩展 ezplatform REST API:https://arfaram.github.io/slides/ezsysztems_meetup_20171130

  • 从特定路径使用特定 contentType ID 导出所有内容。应指定内容字段类型。
  • 如何使用 ValueObjectVisitorInputParser 使用 GET 或 POST 动词

以下列出所需和可选参数以及示例

安装

composer require arfaram/ezrestdemobundle:^1.0
  • 在 AppKernel.php 中激活 Bundle
    public function registerBundles()
    {
        $bundles = array(
            //...
            new Ez\RestDemoBundle\EzRestDemoBundle(),

  • 将 Bundle 路由添加到 routing.yml
ez_rest:
    resource: "@EzRestDemoBundle/Resources/config/routing.yml"
    prefix:   /
  • 清除缓存
php app/console cache:clear

请求参数

必需

  • subtree:指定从何处获取内容的地点。(默认:2)
  • fields:在此演示中仅支持 ezstring, ezrichtext 和 ezimage 字段。

可选

  • limit:要返回的内容项数
  • sort:内容名称排序。可能的值:ASCDESC。(默认:ASC
  • lang:内容语言(例如 ger-DE
  • hiddentruefalse 获取可见或隐藏内容。(默认:false
  • image_variation:(默认:original

GET 示例

Method: GET
Host:http://wwww.domain.com/api/ezp/v2/ez_rest/contentTypeContent/GET/48?&limit=2&subtree=99&fields=title,summary,description,main_image&sort=DESC&lang=ger-DE&image_variation=small&hidden=false

Accept:application/xml

-> 返回内容类型 ID 为 48 且父位置 ID 为 99 的内容。

以下显示 XML 和 JSON 示例

POST 示例

Method: POST
Host:http://wwww.domain.com/api/ezp/v2/ez_rest/contentTypeContent/POST

X-CSRF-Token:xxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type:application/vnd.custom.ContentTypeContentList
Accept:application/xml

XML 负载

<?xml version="1.0" encoding="utf-8"?>
<ContentTypeContentList>
    <contentTypeId>50</contentTypeId>
    <limit>2</limit>
    <subtree>109</subtree>
    <sort>DESC</sort>
    <hidden>false</hidden>
    <lang>ger-DE</lang>
    <image_variation>small</image_variation>
    <fields>
    	<field>
    		<fieldDefinitionIdentifier>title</fieldDefinitionIdentifier>
    	</field>
     	<field>
    		<fieldDefinitionIdentifier>summary</fieldDefinitionIdentifier>
    	</field>
     	<field>
    		<fieldDefinitionIdentifier>description</fieldDefinitionIdentifier>
    	</field>
    	<field>
    		<fieldDefinitionIdentifier>main_image</fieldDefinitionIdentifier>
    	</field>
    </fields>
</ContentTypeContentList>

XML 输出示例

<?xml version="1.0" encoding="UTF-8"?>
<contentList media-type="application/vnd.ez.api.contentList+xml">
    <content media-type="application/vnd.ez.api.content+xml">
        <contentId>101</contentId>
        <contentTypeId>48</contentTypeId>
        <identifier>blog_post</identifier>
        <language>ger-DE</language>
        <publishedDate>2017-07-09T22:15:13+02:00</publishedDate>
        <uri>/Trips/Article</uri>
        <categoryPath>/1/2/94/95/99/101/</categoryPath>
        <mainLocation media-type="application/vnd.ez.api.mainLocation+xml" href="/api/ezp/v2/content/locations/1/2/94/95/99/101/"/>
        <locations media-type="application/vnd.ez.api.locations+xml" href="/api/ezp/v2/content/objects/101/locations"/>
        <title>Article</title>
        <summary>&lt;![CDATA[&lt;section xmlns=&quot;http://ez.no/namespaces/ezpublish5/xhtml5&quot;&gt;&lt;p&gt;THE SUMMARY.&lt;/p&gt;&lt;/section&gt;
]]&gt;</summary>
        <description>&lt;![CDATA[&lt;section xmlns=&quot;http://ez.no/namespaces/ezpublish5/xhtml5&quot;&gt;&lt;p&gt;THE DESCRIPTION&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/section&gt;
]]&gt;</description>
        <main_image>http://www.domain.com/var/site/storage/images/_aliases/small/7/7/4/0/477-1-ger-DE/article.jpg</main_image>
    </content>
</contentList>

JSON 输出示例

Accept:application/json
{
    "contentList": {
        "_media-type": "application/vnd.ez.api.contentList+json",
        "content": [
            {
                "_media-type": "application/vnd.ez.api.content+json",
                "contentId": 101,
                "contentTypeId": 48,
                "identifier": "blog_post",
                "language": "ger-DE",
                "publishedDate": "2017-07-09T22:15:13+02:00",
                "uri": "/Trips/Article",
                "categoryPath": "/1/2/94/95/99/101/",
                "mainLocation": {
                    "_media-type": "application/vnd.ez.api.mainLocation+json",
                    "_href": "/api/ezp/v2/content/locations/1/2/94/95/99/101/"
                },
                "locations": {
                    "_media-type": "application/vnd.ez.api.locations+json",
                    "_href": "/api/ezp/v2/content/objects/101/locations"
                },
                "title": "Article",
                "summary": "<![CDATA[<section xmlns=\"http://ez.no/namespaces/ezpublish5/xhtml5\"><p>THE SUMMARY.</p></section>\n]]>",
                "description": "<![CDATA[<section xmlns=\"http://ez.no/namespaces/ezpublish5/xhtml5\"><p>THE DESCRIPTION</p></section>\n]]>",
                "main_image": "http://www.domain.com/var/site/storage/images/_aliases/small/7/7/4/0/477-1-ger-DE/article.jpg"
            }
        ]
    }
}