Customizing API

We are using the API Platform to create all endpoints in Sylius API. API Platform allows configuring an endpoint by yaml and xml files or by annotations. In this guide, you will learn how to customize Sylius API endpoints using xml configuration.

Introduction

How to prepare project for customization?

If your project was created before v1.10, make sure your API Platform config follows the one below:

# config/packages/api_platform.yaml
api_platform:
    mapping:
        paths:
            - '%kernel.project_dir%/vendor/sylius/sylius/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources'
            - '%kernel.project_dir%/config/api_platform'
            - '%kernel.project_dir%/src/Entity'
    patch_formats:
        json: ['application/merge-patch+json']
    swagger:
        versions: [3]

Also, if you’re planning to modify serialization add this code to framework config:

# config/packages/framework.yaml
//...
serializer:
    mapping:
        paths: [ '%kernel.project_dir%/config/serialization' ]