Update Complete guide to Integrate Symfony 5.2 with angular 9.0.0
I am starting a series of blog articles about Symfony and Angular. This first article is about how to integrate Symfony 5.2 with Angular 9.0.0.
Part one: Backend
- Create a new API project
Create a new API project because we are going to build an API, we will create a symfony project without the — full :
symfony new backend-api
orcomposer create-projectsymfony/skeleton backend-api
- Install API platform
API Platform contains a PHP library (Core) to create fully-featured hypermedia (or GraphQL) web APIs supporting industry-leading standards: JSON-LD with Hydra, OpenAPI…
API Platform also provides ambitious JavaScript tools to create web and mobile applications based on the most popular frontend technologies in a snap. These tools parse the documentation of the API (or of any other API supporting Hydra or OpenAPI).
Install the API Platform’s server component in this skeleton:
composer require api
Then, create the database and its schema:
php bin/console doctrine:database:create
php bin/console doctrine:schema:create
NB : do not forget to configure your .env file in your Symfony project
Install LexikJWTAuthenticationBundle :
In order to create JWT authentication with API Platform we will install a specific bundle : LexikJWTAuthenticationBundle here is the official documentation https://github.com/lexik/LexikJWTAuthenticationBundle.
If you ever faced problems with the documentation of this bundle , Here is an example of security.yaml file that I made :
Install NelmioCorsBundle :
The NelmioCorsBundle allows you to send Cross-Origin Resource Sharing headers with ACL-style per-URL configuration.
Official documentation :
https://github.com/nelmio/NelmioCorsBundle
Create our first end-point :
Let’s now create our first endpoint for users, first thing first we will create a User Entity then add @Api platform decorator.
Our User has these pieces of information: username, email, and a password
Before starting to run these commands, make sure that you have the maker-bundle.
If you have, then let's start :
- Create a user entity and fill the answers :
php bin/console make:entity
Make a migration :
php bin/console make:migration
Execute the migration :
php bin/console doctrine:migration:migrate
For more details about Databases and the Doctrine ORM : https://symfony.com/doc/current/doctrine.html
Using Postman, we test our backend :
let’s run first our server : php -S 127.0.0:8000 -t public
http://127.0.0.1:8000/api/login
Conclusion :
In this first part, we create a simple project with our first endpoint for users, and then we installed the necessary bundles in order to generate the token.
Next part : http://www.dopeside.io/symfony-6-1-and-angular-15-0-1/