Faisal Hotak
Faisal Hotak

Reputation: 435

Symfony Api Platform /api not showing the api page correctly

I'm working on a Symfony Project. I had to install the API PLATFORM. So I did a

composer require api

Then when I want to access my /api with localhost:8000/api, it shows me this code

{"resourceNameCollection":["App\\Entity\\User"]}

with a white page, nothing more.

enter image description here

My question is why is it not showing this instead ?

enter image description here

My routes/api_platform.yaml

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

My packages/api_platform.yaml

api_platform:
title: 'Symfony REST API'
description: 'A Symfony API.'
version: '1.0.0'
mapping:
    paths: ['%kernel.project_dir%/src/Entity']
swagger:
    versions: [3]
patch_formats:
    json: ['application/json']
eager_loading:
    force_eager: false
formats:
    json:
        mime_types: ['application/json']
    multipart:
        mime_types: ['multipart/form-data']
collection:
    pagination:
        enabled: false

My security.yaml

security:
encoders:
    App\Entity\User:
        algorithm: bcrypt

providers:
    users_in_memory: { memory: null }
    users_in_database:
        entity:
            class: 'App\Entity\User'
            property: "username"

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        anonymous: true
        provider: users_in_database

        form_login:
            login_path: security_login
            check_path: security_login

        logout:
            path: security_logout
            target: home

access_control:

Upvotes: 0

Views: 3157

Answers (1)

Faisal Hotak
Faisal Hotak

Reputation: 435

I found the problem.

In my 'packages/api_platform.yaml', I added

html:
        mime_types: ['text/html']

In the formats like this

formats:
    json:
        mime_types: ['application/json']
    jsonld:
        mime_types: ['application/ld+json']
    html:
        mime_types: ['text/html']
    multipart:
        mime_types: ['multipart/form-data']

So basically it needed the html format to render the page, I guess.

Upvotes: 2

Related Questions