voryx/restgeneratorbundle
Composer 安装命令:
composer require voryx/restgeneratorbundle
包简介
REST API Generator for Symfony 2
README 文档
README
About
A CRUD like REST Generator
Features
- Generators RESTful action from entity
- Simplifies setting up a RESTful Controller
Installation
Require the "voryx/restgeneratorbundle" package in your composer.json and update your dependencies.
$ php composer.phar require voryx/restgeneratorbundle dev-master
Add the VoryxRestGeneratorBundle to your application's kernel along with other dependencies:
public function registerBundles() { $bundles = array( //... new Voryx\RESTGeneratorBundle\VoryxRESTGeneratorBundle(), new FOS\RestBundle\FOSRestBundle(), new JMS\SerializerBundle\JMSSerializerBundle($this), new Nelmio\CorsBundle\NelmioCorsBundle(), //... ); //... }
Configuration
This bundle depends on a number of other Symfony bundles, so they need to be configured in order for the generator to work properly
framework: csrf_protection: false #only use for public API fos_rest: routing_loader: default_format: json param_fetcher_listener: true body_listener: true #disable_csrf_role: ROLE_USER body_converter: enabled: true view: view_response_listener: force nelmio_cors: defaults: allow_credentials: false allow_origin: [] allow_headers: [] allow_methods: [] expose_headers: [] max_age: 0 paths: '^/api/': allow_origin: ['*'] allow_headers: ['*'] allow_methods: ['POST', 'PUT', 'GET', 'DELETE'] max_age: 3600 sensio_framework_extra: request: { converters: true } view: { annotations: false } router: { annotations: true }
Generating the Controller
Generate the REST controller
$ php app/console voryx:generate:rest
This will guide you through the generator which will generate a RESTful controller for an entity.
Example
Create a new entity called 'Post':
$ php app/console doctrine:generate:entity --entity=AppBundle:Post --format=annotation --fields="name:string(255) description:string(255)" --no-interaction
Update the database schema:
$ php app/console doctrine:schema:update --force
Generate the API controller:
$ php app/console voryx:generate:rest --entity="AppBundle:Post"
Using the API
If you selected the default options you'll be able to start using the API like this:
Creating a new post (POST)
$ curl -i -H "Content-Type: application/json" -X POST -d '{"name" : "Test Post", "description" : "This is a test post"}' http://localhost/app_dev.php/api/posts
Updating (PUT)
$ curl -i -H "Content-Type: application/json" -X PUT -d '{"name" : "Test Post 1", "description" : "This is an updated test post"}' http://localhost/app_dev.php/api/posts/1
Get all posts (GET)
$ curl http://localhost/app_dev.php/api/posts
Get one post (GET)
$ curl http://localhost/app_dev.php/api/posts/1
Delete (DELETE)
$ curl -X DELETE http://localhost/app_dev.php/api/posts/1
Related Entities
If you want the form to be able to convert related entities into the correct entity id on POST, PUT or PATCH, use the voryx_entity form type
#Form/PostType() ->add( 'user', 'voryx_entity', array( 'class' => 'Acme\Bundle\Entity\User' ) )
voryx/restgeneratorbundle 适用场景与选型建议
voryx/restgeneratorbundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 142.92k 次下载、GitHub Stars 达 177, 最近一次更新时间为 2014 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 voryx/restgeneratorbundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 voryx/restgeneratorbundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 142.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 179
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-03-13