Video Tutorial Comment module: API Platform


Welcome to this video where I suggest you discover how to make several technologies coexist together and we will see how to create a dynamic comment system using Symfony (with API Platform) and React.

The objective is to replace a comment system generated on the server side, to set up a dynamic system which will only be loaded when the user reaches the bottom of the page. This will allow us to avoid diluting the keywords of our content for SEO and will also allow us to improve the performance of our application by loading less default content.

First we will set up an API to retrieve all of the comments from our application. To create this API we will use the API Platform module which allows to generate a REST API by annotating the entities. We will need to create several entry points:

Retrieving comments (filtered by article and paginated)

Creation of a comment (requires authentication)

Modification of a comment (only if the person connected is the author of the comment)

Deleting a comment (only if the person connected is the author of the comment)

For the retrieval part, we will make sure that we can retrieve the comments associated with an article and we will also add a paging system. We can use the JSON-LD format for this, which allows us to return additional information about our resources. This format will allow us to expose the path (IRI) to the linked resources (following page, previous page, path of a resource ...) as well as the total number of elements. This will be very useful when you have to create the interface.