Comparing API Platform and Symfony Encore with ReactJS
Tags: api, javascript, symfony, react
Published: 2020-04-13 01:41:32

---
title: Comparing API Platform and Symfony Encore with ReactJS
published: true
date: 2019-10-04 18:13:32 UTC
tags: api,javascript,symfony,react
canonical_url: https://sidoine.org/comparing-api-platform-and-symfony-encore-with-reactjs
---

![](https://cdn-images-1.medium.com/max/1024/0*mOJrxqzAkE7LgKmo)<figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;utm_medium=referral">Clément H</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

This article have been written in Oct 2019 and the goal is to compare **at this date** the main differences between the 2 projects. No proper comparison have be found _yet_ by myself, so I am writing one !

### Symfony

It is a PHP framework that allow to produce webapp, web API, etc. Backed by Sensio Labs. More details here [https://symfony.com](https://symfony.com).

### Symfony Encore

It is a Symfony package that allow to use frontend javascript inside Symfony. It allow using ReactJS within Symfony. Here is some example and the official documentation:

- [https://symfony.com/doc/current/frontend/encore/simple-example.html](https://symfony.com/doc/current/frontend/encore/simple-example.html)
- [https://symfony.com/doc/current/frontend/encore/reactjs.html](https://symfony.com/doc/current/frontend/encore/reactjs.html)
- [https://auth0.com/blog/developing-modern-apps-with-symfony-and-react/#Building-the-Frontend-App-with-React](https://auth0.com/blog/developing-modern-apps-with-symfony-and-react/#Building-the-Frontend-App-with-React)
- [https://medium.com/@lmatte7/how-to-use-react-with-symfony-4-88fb27abf5e5](https://medium.com/@lmatte7/how-to-use-react-with-symfony-4-88fb27abf5e5)

It is possible to have a Single Page Application or to create multiple React app inside the same Symfony package. You must run the symfony server and the encore app when you are developing on the application. There is no ‘auto-refresh’ feature like you have on a CRA React app.

![](https://cdn-images-1.medium.com/max/1024/1*JNXkUF-GiQCEPxGW9e5bUg.png)

### API Platform

API Platform is an developement environnement, based on Symfony, that allow to create and deploy an application with an API backend (REST or GraphQL), and a frontend (React by default). It is API-first in mind.

The documentation is here [https://api-platform.com](https://api-platform.com).

The development environment is based on Docker containers, and it has been developed to make it easy to deploy on cloud ready systems (like k8n or other).

![](https://cdn-images-1.medium.com/max/1024/1*rxjwaeRe5eDIFCrMIETk_Q.png)

There is no way in this project to use the ‘default’ template layout of Symfony, you must have a SPA application. There is only one React app needed !

### Which one to choose ?

This is an hard point. Each solution comes with specific advantages.

The API part of API Platform is in fact a composer package that you can easily install on a existing Symfony platform ( composer require api ). You will then be able to use the very powerful annotation @ApiRessource to present any entity as full CRUD REST API ([see here](https://api-platform.com/docs/core/getting-started/#mapping-the-entities)).

I think it is easier to integrate slowly a ReactJS frontend with Symfony Encore, as you can keep your codebase and existing templates. But API Platform is more powerful when starting brand new project that will need a webapp and a mobile app.

What is your choice ? Let me know !