8000 GitHub - sjunior-dev/symfony-api-test at d082e7d558062bfedb8cc6275077c6bb55106bb5
[go: up one dir, main page]

Skip to content

sjunior-dev/symfony-api-test

Repository files navigation

Symfony API

Bootstrapping.

composer create-project symfony/skeleton:"7.0.*" symfony-api-test

# install dev dependencies
composer require --dev doctrine/doctrine-fixtures-bundle phpunit/phpunit symfony/browser-kit symfony/css-selector symfony/debug-bundle symfony/maker-bundle symfony/phpunit-bridge symfony/stopwatch symfony/web-profiler-bundle zenstruck/foundry

# add doctrine migrations
composer require doctrine/doctrine-migrations-bundle

# add symfony messenger for async
composer require symfony/messenger symfony/doctrine-messenger

# add security recipe
composer require security

# add UUID for public IDs
composer require symfony/uid

# add JWT Auth
composer require lexik/jwt-authentication-bundle

Commands and Run

# Run the application on Docker ([http://localhost](localhost))
docker compose up

# fixtures
php bin/console doctrine:fixtures:load --no-interaction

Application Structure

src/
├── Controller
│   ├── UserAdminController.php
│   └── UserController.php
├── DataFixtures
│   └── AppFixtures.php
├── Entity
│   ├── Trait
│   └── User.php
├── Error
│   └── Normalizer.php
├── Factory
│   └── UserFactory.php
├── Kernel.php
├── Repository
│   └── UserRepository.php
├── Response
│   └── UserResponse.php
└── Service
    └── UserService.php

For Authentication I'm used lexik/jwt-authentication-bundle which also provides the login route /api/login_check.

Users are created with different roles using fixtures and will be created during container launch.

I've decided to differentiate admin routes to user routes, so access control are simplified.

Unified User Response

{
  "data": {
    "id": "b0393b4c-d213-40fa-8a7c-ab30f5a3eb99",
    "email": "sjunior.admin@gmail.com",
    "roles": [
      "ROLE_ADMIN",
      "ROLE_USER"
    ]
  }
}

Docker and tests

# run migration for test environment
docker compose exec app-default php bin/console --env=test do:mi:mi

# run phpunit
docker compose exec app-default php vendor/bin/phpunit

# run any other command
docker compose exec app-default <command>

# log into the container
docker compose exec app-default /bin/sh

Rest Client VSCode

Add it here Configuration files are:

  • user-admin.http
  • user.http

About

Symfony API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  
0