nedra/rest-bundle

基于您的实体生成REST API

安装: 15

依赖项: 0

建议者: 0

安全: 0

星标: 5

关注者: 3

分支: 0

开放问题: 2

类型:symfony-bundle

1.3.9 2017-09-29 14:13 UTC

This package is not auto-updated.

Last update: 2024-09-22 09:38:56 UTC


README

Build Status

NedraRestBundle

NedraRestBundle 可根据您的模型自动创建REST API。只需提供您的模型并使用自动生成的端点。

入门指南

Bundle在基于Doctrine ORM的模型上运行。Bundle的目的是以最快、最简单的方式生成REST API。

安装

步骤 1: 更新composer.json

composer require nedra/rest-bundle

步骤 2: 在AppKernel中注册类

[...]
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle($this),
new Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(),
new Nedra\RestBundle\NedraRestBundle(),

步骤 3: 更新config.yml以配置NedraRestBundle

nedra_rest:
    active: true # this is default value, you can disable the bundle with set to false
    entities:
        app.model:
            classes:
                model: AppBundle\Entity\Model

注意

app.model是一个模式示例。您必须使用应用前缀(如app)定义您的模型

检查路由

运行该命令并调试您的路由器

bin/console debug:router

您将看到自动生成的REST路由

app_model_index             GET         ANY      ANY    /models/                            
app_model_create            POST        ANY      ANY    /models/new                         
app_model_update            PUT|PATCH   ANY      ANY    /models/{id}                        
app_model_show              GET         ANY      ANY    /models/{id}                        
app_model_delete            DELETE      ANY      ANY    /models/{id} 

配置参考

nedra_rest:
    entities:
        app.model:
            path: model # you can change /models/ to /cars/
            except: ['show']
            only: ['create', 'index']
            classes:
                model: AppBundle\Entity\Model
                form:  AppBundle\Form\ModelType

注意

您只能使用其中的一个:`except`或`only`