baldeweg/api-bundle

此包已被弃用且不再维护。未建议替代包。

提供API工具。

安装: 617

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

类型:symfony-bundle

v55.0.3 2023-09-19 15:35 UTC

README

提供API工具。

入门指南

composer req baldeweg/api-bundle

如果未自动完成,请在config/bundles.php中激活此包。

Baldeweg\Bundle\ApiBundle\BaldewegApiBundle::class => ['all' => true],

用法

use Baldeweg\Bundle\ApiBundle\AbstractApiController;
use Baldeweg\Bundle\ApiBundle\Response;

$response = new Response();

// Contains the keys of the entity you need
$fields = ['id', 'name', 'user' => ['id'], 'createdAtTimestamp', 'commentsCount'];

// JSON Response with serialized data
$response->single($fields, $genre); // single entity
$response->collection($fields, $genres); // array of entities
$response->invalid(); // Return message and 400 status code
$response->deleted(); // Return message and 200 status code

// Parse the data from the request and make them available to the form
$this->submitForm($request)

测试特质

为了使XHR请求更容易,提供了一个可用的ApiTestTrait特质。

use \Baldeweg\Bundle\ApiBundle\ApiTestTrait;

生成器

  • make:api:controller - 创建控制器
  • make:api:test - 创建测试