4.6 API Platform Migration
If your API resources are defined via PHP attributes only, you can skip this step. For XML/YAML resource definitions, migrate to the new Metadata format used by API Platform 4.
1. XML: update namespace & XSD
Before:
<resources xmlns="https://api-platform.com/schema/metadata"
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
After:
<resources xmlns="https://api-platform.com/schema/metadata/resources-3.0"
xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0 https://api-platform.com/schema/metadata/resources-3.0/resources-3.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2. Convert operations structure (unify to operations
)
operations
)API Platform 3/4 uses a single operations
node and Metadata classes (ApiPlatform\Metadata\Get
, GetCollection
, Post
, Put
, Patch
, Delete
).
HTTP method is implied by the class; custom paths use uriTemplate
.
XML — from collectionOperations/itemOperations
→ operations
collectionOperations/itemOperations
→ operations
Before:
<resource class="Plugin\Entity\Term" shortName="Term">
<collectionOperations>
<collectionOperation name="get" />
<collectionOperation name="post">
<attribute name="path">/plugin/terms</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations>
<itemOperation name="get" />
<itemOperation name="put" />
</itemOperations>
</resource>
After:
<resource class="Plugin\Entity\Term" shortName="Term">
<operations>
<operation name="plugin_terms_get_collection"
class="ApiPlatform\Metadata\GetCollection"
uriTemplate="/plugin/terms" />
<operation name="plugin_terms_post"
class="ApiPlatform\Metadata\Post"
uriTemplate="/plugin/terms" />
<operation name="plugin_terms_get"
class="ApiPlatform\Metadata\Get"
uriTemplate="/plugin/terms/{id}" />
<operation name="plugin_terms_put"
class="ApiPlatform\Metadata\Put"
uriTemplate="/plugin/terms/{id}" />
</operations>
</resource>
3. Providers / processors (only if you use them)
If you referenced custom providers/persisters before, align them with the state provider/processor model.
Last updated
Was this helpful?