API PLATFORM WITH SYMFONY

This repository provides a step-by-step guide to set up an API platform using Symfony. It includes the installation of required packages, creation of entities, and execution of migrations.

Installation

  1. Install a new Symfony project:

    symfony new ApiPlateform
  2. Navigate to the project directory:

    cd ApiPlateform
  3. Install the API platform:

    symfony composer req api
  4. Install ORM, Migration, Maker, Fixtures, and Testing:

    symfony composer req orm
    symfony composer req migrations
    symfony composer req --dev make
    symfony composer req --dev orm-fixtures
    symfony composer req --dev test
  5. Install JWT (Json Web Token) authentication:

    symfony composer req lexik/jwt-authentication-bundle
  6. Install Faker (generates fake data for testing):

    • Please follow the installation instructions provided by Faker to install the package.

    • Run the following command to install the package:

    composer require --dev fzaninotto/faker

Entities

  1. Create the User entity:

    bin/console make:user
  2. Create the Article entity:

    bin/console make:entity Article

Migrations

  1. Generate a migration:

    symfony console make:migration
  2. Execute the migration to update the database schema:

    bin/console doctrine:migrations:migrate

Run Fake data

php bin/console  doctrine:fixtures:load

Run App

   symfony server:start

go to =>http://127.0.0.1:8000/api

Run testUnit

bin/phpunit

Error in Groups of serialization :

bin/console cache:clear

normalizationContext vs denormalizationContext:


normalizationContext:['groups'=>['user:read']]=> indicating that only properties annotated with this group should be included in the normalized output(get/getcollection) ex: #[Groups(['user:write'])] {"email": "ypouros@hotmail.com", }

denormalizationContext:['groups'=>['user:write']]=>when deserializing input data. (post/put/patch) #[Groups(['user:write'])] { "email": "string" }