Symfony 4 PHP REST API JWT Example, Symfony 4 REST API boilerplate, Json Web Tokens authentication REST API. How to implement REST API using Symfony framework. PHP Phalcon REST API example.

Hello my friends!

Recently I needed to create a JWT based REST API using Symfony framework.

So here is my take on it: https://github.com/vgrankin/symfony_4_jwt_restapi_demo

This project is created using PHP 7, Symfony 4, MariaDB, Firebase JWT library, PHPUnit and Guzzle library  (which is used by PHPUnit tests to test API endpoints).

I tried to include as much documentation as possible for you to easily pick up the code (you need to be familiar with Symfony though, but if you aren’t there is still good information for you – for example you can look at /src/Service/AuthService.php to get idea on how to use Firebase JWT library to create and validate JWT tokens). So if you are thinking of implementing REST API JWT based “bycicle”, check this repository out! It also is made with best REST API practices in mind btw! So a lot of interesting stuff is there in the code!

As a bonus you can also check my other repository, which is also a REST API JWT microservice, which uses Phalcon PHP framework and MongoDB. Here is a link: https://github.com/vgrankin/phalcon_jwt_restapi_demo. One note though is that probably it is better to look at Symfony 4 implementation if you want to follow REST API standards more or less strictly (or at least if you are looking for consistency), because my Phalcon based implementation is not heavily relying on REST API guidelines (but README.md of this repository mentions what needs to be improved). That said Phalcon implementation still is a good example of how JWT based REST API can be implemented and how to use Phalcon PHP framework for that.

Hope it helps! Cheers! 🙂

Leave a comment