API Platform comes with a set of maker commands to help you create API Resources and other related classes.
You can use Symfony
MakerBundle to
generate a Doctrine entity that is also a resource thanks to the --api-resource option:
bin/console make:entity --api-resourceYou can create an API Filter class using the following command:
bin/console make:filter <type> <name>Where <type> is the filter type and <name> is the name of the filter class. Supported types are
orm and odm
Elasticsearch filters are not yet supported
You can create a State Provider class using the following command:
bin/console make:state-provider <name>You can create a State Processor class using the following command:
bin/console make:state-processor <name>You can disable the maker commands by setting the following configuration in your
config/packages/api_platform.yaml file:
api_platform:
maker: falseBy default, the maker commands are enabled if the maker bundle is detected.
The makers creates all classes in the configured maker bundle root_namespace (default App).
Filters are created in App\\Filter State Providers are created in App\\State State Processors
are created in App\\State
Should you customize the base namespace for all API Platform generated classes you can so in 2 ways:
To change the default namespace prefix (relative to the maker.root_namespace), you can set the
following configuration in your config/packages/api_platform.yaml file:
api_platform:
maker:
namespace_prefix: "Api"You can override the default namespace prefix by using the --namespace-prefix option when running
the maker commands:
bin/console make:filter orm MyCustomFilter --namespace-prefix Api\\Filter
bin/console make:state-provider MyProcessor --namespace-prefix Api\\State
bin/console make:state-processor MyProcessor --namespace-prefix Api\\StateNamespace prefixes passed to the cli command will be relative to the maker.root_namespace
and not the configured API Platform namepace_prefix.
You can also help us improve the documentation of this page.
Made with love by
Les-Tilleuls.coop can help you design and develop your APIs and web projects, and train your teams in API Platform, Symfony, Next.js, Kubernetes and a wide range of other technologies.
Learn more