steffenbrem/json-api-bundle
Composer 安装命令:
composer require steffenbrem/json-api-bundle
包简介
Integration of JSON API with Symfony2 using JMS Serializer (FOSRestBundle).
README 文档
README
Integration of JSON API with Symfony 2 (FOSRestBundle)
Note that this is stil a WIP and should not be used for production!
Usage
Coming soon
If you want to experiment with this implementation, you can just enable this bundle in your AppKernel and everything should work directly. Try to serialize some annotated php classes and check it out!
Configuration reference
mango_json_api: show_version_info: true # default base_uri: /api # default
Annotations
@Resource
This will define your class as a JSON-API resource, and you can optionally set it's type name.
This annotation can be defined on a class.
use Mango\Bundle\JsonApiBundle\Configuration\Annotation as JsonApi; /** * @JsonApi\Resource(type="posts", showLinkSelf=true) */ class Post { // ... }
| Property | Default | Required | Content | Info |
|---|---|---|---|---|
| type | ~ | No | string | If left default, it will resolve its type dynamically based on the short class name. |
| showLinkSelf | true | No | boolean | Add self link to the resource |
@Id (optional, it defaults to id)
This will define the property that will be used as the id of a resource. It needs to be unique for every resource of the same type.
This annotation can be defined on a property.
use Mango\Bundle\JsonApiBundle\Configuration\Annotation as JsonApi; /** * @JsonApi\Resource(type="posts") */ class Post { /** * @JsonApi\Id */ protected $uuid; }
@Relationship
This will define a relationship that can be either a oneToMany or manyToOne. Optionally you can set includeByDefault to include (sideload) the relationship with it's primary resource.
This annotation can be defined on a property.
use Mango\Bundle\JsonApiBundle\Configuration\Annotation as JsonApi; /** * @JsonApi\Resource(type="posts") */ class Post { // .. /** * @JsonApi\Relationship(includeByDefault=true, showLinkSelf=false, showLinkRelated=false) */ protected $comments; }
| Property | Default | Required | Content | Info |
|---|---|---|---|---|
| includeByDefault | false | No | boolean | This will include (sideload) the relationship with it's primary resource |
| showData | false | No | boolean | Shows data, which consists of ids of the relationship data |
| showLinkSelf | false | No | boolean | Add self link of the relationship |
| showLinkRelated | false | No | boolean | Add related link of the relationship |
Configuration Reference
# app/config/config.yml mango_json_api: show_version_info: true
Example response
GET /api/channels
{
"jsonapi": {
"version": "1.0"
},
"meta": {
"page": 1,
"limit": 10,
"pages": 1,
"total": 4
},
"data": [
{
"type": "channels",
"id": 5,
"attributes": {
"code": "WEB-UK",
"name": "UK Webstore",
"description": null,
"url": "localhost",
"color": "Blue",
"enabled": true,
"created-at": "2015-07-16T12:11:50+0000",
"updated-at": "2015-07-16T12:11:50+0000",
"locales": [],
"currencies": [],
"payment-methods": [],
"shipping-methods": [],
"taxonomies": []
},
"relationships": {
"workspace": {
"data": {
"type": "workspaces",
"id": 18
}
}
}
},
{
"type": "channels",
"id": 6,
"attributes": {
"code": "WEB-NL",
"name": "Dutch Webstore",
"description": null,
"url": null,
"color": "Orange",
"enabled": true,
"created-at": "2015-07-16T12:11:50+0000",
"updated-at": "2015-07-16T12:11:50+0000",
"locales": [],
"currencies": [],
"payment-methods": [],
"shipping-methods": [],
"taxonomies": []
},
"relationships": {
"workspace": {
"data": {
"type": "workspaces",
"id": 18
}
}
}
},
{
"type": "channels",
"id": 7,
"attributes": {
"code": "WEB-US",
"name": "United States Webstore",
"description": null,
"url": null,
"color": "Orange",
"enabled": true,
"created-at": "2015-07-16T12:11:50+0000",
"updated-at": "2015-07-16T12:11:50+0000",
"locales": [],
"currencies": [],
"payment-methods": [],
"shipping-methods": [],
"taxonomies": []
},
"relationships": {
"workspace": {
"data": {
"type": "workspaces",
"id": 18
}
}
}
},
{
"type": "channels",
"id": 8,
"attributes": {
"code": "MOBILE",
"name": "Mobile Store",
"description": null,
"url": null,
"color": "Orange",
"enabled": true,
"created-at": "2015-07-16T12:11:50+0000",
"updated-at": "2015-07-16T12:11:50+0000",
"locales": [],
"currencies": [],
"payment-methods": [],
"shipping-methods": [],
"taxonomies": []
},
"relationships": {
"workspace": {
"data": {
"type": "workspaces",
"id": 18
}
}
}
}
],
"included": [
{
"type": "workspaces",
"id": 18,
"attributes": {
"name": "First Workspace"
},
"relationships": {
"channels": {
"links": {
"related": "/workspaces/18/channels"
}
}
}
}
]
}
steffenbrem/json-api-bundle 适用场景与选型建议
steffenbrem/json-api-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.48k 次下载、GitHub Stars 达 53, 最近一次更新时间为 2015 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「jsonapi」 「JSON-API」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 steffenbrem/json-api-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 steffenbrem/json-api-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 steffenbrem/json-api-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Serializer transformers outputting valid API responses in JSON, JSON API and HAL+JSON API formats.
Symfony 2 & 3 JSON API Transformer Package
PHP-code generator (based on OAS) for Laravel framework, with complete support of JSON-API data format
The jsonapi-querifier-bundle offers the Querifer filter syntax for the paknahad/jsonapi-bundle.
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
统计信息
- 总下载量: 9.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 54
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-04