Skip to content

Symfony 7: API

Implementation

Simple: return JSON from controller

  • Works out of the box;
  • Improvement: add serializer (better work with objects, private properties);
composer require serializer

Complex: API Platform

composer require api
 api-platform/symfony  instructions:

  * Your API is almost ready:
    1. Create your first API resource in src/ApiResource;
    2. Go to /api to browse your API

  * Using MakerBundle? Try php bin/console make:entity --api-resource 

  * To enable the GraphQL support, run composer require api-platform/graphql,
    then browse /api/graphql.

  * Read the documentation at https://api-platform.com/docs/

Entity:

#[ApiResource]

Debug

  • Use profiler general page: https://127.0.0.1:8001/_profiler/
  • shows list of all requests, including API;
# current configuration:
syc debug:config api_platform

# all possible configuration:
syc config:dump api_platform

Notes

- Endpoints / operations;