polidog / simple-api-bundle
Simple API
Installs: 1 790
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 1
Open Issues: 0
Requires
- php: ^7.1
- ext-json: *
- doctrine/common: ^2.6
- jms/serializer: ~1.10|~2.1|~2.2|~3.0
- symfony/config: ^3.4|^4.4
- symfony/dependency-injection: ^3.4|^4.4
- symfony/event-dispatcher: ^3.4|^4.4
- symfony/http-foundation: ^3.4|^4.4
- symfony/http-kernel: ^3.4|^4.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- phpunit/phpunit: ^7.3
README
Installation
$ composer require polidog/simple-api-bundle "dev-master"
Add config/bundles.php
<?php return [ ... Polidog\SimpleApiBundle\PolidogSimpleApiBundle::class => ['all' => true] ];
Introduce bundle configuration to your config file
# config/packages/polidog_simple_api.yml polidog_simple_api: ~
Usage
<?php declare(strict_types=1); namespace App\Controller\Api; use App\Entity\LoginUser; use Polidog\SimpleApiBundle\Annotations\Api; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; class UserController { private $userRepository; /** * for php7 * @Route("/user/{id}") * @Api() */ #[Route('/user/{$id}', name: 'app_user')] #[Api] public function me($id): array { $user = $this->userRepository->find($id); return [ 'id' => $user->getId(), 'name' => $user->getUsername(), 'avatar' => $user->getAvatar(), ]; } /** * for php7 * @Route("/user/post", methods={"POST"}) * @Api(statusCode=201) */ #[Route('/user/post', name: 'POST')] #[Api(201)] public function post(Request $request): array { // TODO save logic. return [ 'status' => 'ok', ]; } }