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

Getting "Format 'html' not supported, handler must be implemented" on GET requests #721

Open
medteck opened this issue Dec 9, 2021 · 2 comments

Comments

@medteck
Copy link
Contributor

medteck commented Dec 9, 2021

When I try to retrieve data with A GET request (ex: /shop-api/products/by-code/abc), I'm getting this response from the API :

{
    "code": 401,
    "message": "Invalid credentials."
}

Here's my configuration in config/packages/_sylius_shop_api.yaml :

imports:
    - { resource: "@SyliusShopApiPlugin/Resources/config/app/config.yml" }
    - { resource: "@SyliusShopApiPlugin/Resources/config/app/sylius_mailer.yml" }

# config/packages/fos_rest.yaml

fos_rest:
    view:
        formats:
            json: true
    format_listener:
        rules:
            - { path: '^/shop-api', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
            - { path: '^/api', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
            - { path: '^/', stop: true }

As you can see, the file is as described in the README of the package.

I tried everything I saw on Stackoverflow (related to api_platform) and none of those solutions worked.

@medteck
Copy link
Contributor Author

medteck commented Dec 9, 2021

To make it work, I had to add a line in config/packages/fos_rest.yaml :

fos_rest:
    exception: true
    view:
        formats:
            json: true
            xml:  true
        empty_content: 204
    format_listener:
        rules:
            - { path: '^/shop-api', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true } # <------ Add this line
            - { path: '^/api/v1/.*', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
            - { path: '^/', stop: true }

@mamazu
Copy link
Member

mamazu commented Dec 12, 2021

Thanks for reporting this issue.
Did you figure out the error? It looks like a 401 which doesn't have to do anything with the fos output configuration or the format 'html' not supported.

But nevertheless the /shop-api/products/by-code route should not be protected by any authorization what so ever. This might be because of a missing setting in the security.yaml file.

Since you mentioned API platform. If you are starting a new project with Sylius and an API it is recommended to use the api platform integration of the project instead of this package.

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

No branches or pull requests

2 participants