Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Api Platform Example #57

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

alexander-schranz
Copy link
Member

@alexander-schranz alexander-schranz commented Mar 30, 2020

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets fixes -
Related issues/PRs -
License MIT
Documentation PR -

What's in this PR?

Add example for a api platform entity implemented into sulu.

Why?

It should be possible to use Api Platform should custom entities.

Example Usage

1. Install api-platform/core

composer require api-platform/core

2. Install maker-bundle

composer require maker-bundle

3. Configure api platform package

config/packages/api_platform.yaml

# empty file to avoid symfony flex creating it again

config/packages/api_platform_admin.yaml

Add support for hal and change pagination parameter to limit

api_platform:
    mapping:
        paths: ['%kernel.project_dir%/src/Entity']
    patch_formats:
        json: ['application/merge-patch+json']
    swagger:
        versions: [3]

    # Configure hal support for sulu
    formats:
        jsonhal:
            mime_types:
                - application/hal+json
        json:
            mime_types:
                - application/json
        html:
            mime_types:
                - text/html

    collection:
        pagination:
            client_items_per_page: true
            items_per_page_parameter_name: limit

4. Configure api platform routes

config/routes/api_platform.yaml

# empty file to avoid symfony flex creating it again

config/routes/api_platform_admin.yaml

api_platform:
    resource: .
    type: api_platform
    prefix: /admin/api

5. Create your entity

Create your entity with make:entity and register it as ApiResource

To Do Sulu

@alexander-schranz alexander-schranz added the Example Example implementations label Sep 4, 2020
@niklasnatter niklasnatter removed the Example Example implementations label Oct 28, 2020
@alexander-schranz
Copy link
Member Author

I created an issue on api platform with our current problems. Lets see if maybe api platform can be get there more flexible or we need to introduce some bridge between our and there hal format. api-platform/core#4141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants