wwsh / gastro-api

为桌面和移动应用程序维护的 Gastro API

dev-master 2016-03-17 08:23 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:09:22 UTC


README

此包支持由 wwsh 编写的 Gastro API 的功能,该功能由桌面和移动应用程序指定和使用。

如需更多信息,请联系 Thomas Parys,请访问 此网站

配置

在您的 mail config.yml 中启用 Doctrine ORM,并添加以下 FOSRestBundle 的配置

fos_rest:
    param_fetcher_listener: true
    body_listener: true
    body_converter:
        enabled: true
    format_listener:
        rules:
            - { path: '^/api', priorities: [ json ], fallback_format: json, prefer_extension: true }
            - { path: '^/', priorities: [html, json], fallback_format: html, prefer_extension: false }
    view:
        view_response_listener: 'true'
        mime_types: ['application/json', 'application/json;version=1.0', 'application/json;version=1.1']
        formats:
          json: true
          html: false
          xml:  false
    routing_loader:
        default_format: json
        include_format: false
    exception:
        codes:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
            'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
        messages:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
    access_denied_listener:
        json: true

别忘了在 kernel 中启用这些包

        new \FOS\RestBundle\FOSRestBundle(),
        new JMS\SerializerBundle\JMSSerializerBundle(),
        new \Nelmio\ApiDocBundle\NelmioApiDocBundle(),
        new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),

现在是将路由包含到您的 routing.yml 中的时候了

        api:
            resource: "@ApiBundle/Resources/config/routing.yml"
            type:     rest
            prefix:   /api

您可以自定义前缀,但我建议使用标准前缀。

现在 API 已经设置好了。要创建数据库模式并用示例数据填充,您可以使用

php bin/console database:create
php bin/console doctrine:schema:create
php bin/console doctrine:fixtures:load

在此处检查您的 API 是否工作: API DOC

如有任何疑问,请随时提问。