Chapters
28 Chapters
|
2:51:42
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^3.0", // v3.0.8
"doctrine/annotations": "^1.0", // 1.14.2
"doctrine/doctrine-bundle": "^2.8", // 2.8.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.14", // 2.14.0
"nelmio/cors-bundle": "^2.2", // 2.2.0
"nesbot/carbon": "^2.64", // 2.64.1
"phpdocumentor/reflection-docblock": "^5.3", // 5.3.0
"phpstan/phpdoc-parser": "^1.15", // 1.15.3
"symfony/asset": "6.2.*", // v6.2.0
"symfony/console": "6.2.*", // v6.2.3
"symfony/dotenv": "6.2.*", // v6.2.0
"symfony/expression-language": "6.2.*", // v6.2.2
"symfony/flex": "^2", // v2.2.4
"symfony/framework-bundle": "6.2.*", // v6.2.3
"symfony/property-access": "6.2.*", // v6.2.3
"symfony/property-info": "6.2.*", // v6.2.3
"symfony/runtime": "6.2.*", // v6.2.0
"symfony/security-bundle": "6.2.*", // v6.2.3
"symfony/serializer": "6.2.*", // v6.2.3
"symfony/twig-bundle": "6.2.*", // v6.2.3
"symfony/ux-react": "^2.6", // v2.6.1
"symfony/validator": "6.2.*", // v6.2.3
"symfony/webpack-encore-bundle": "^1.16", // v1.16.0
"symfony/yaml": "6.2.*" // v6.2.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.2
"symfony/debug-bundle": "6.2.*", // v6.2.1
"symfony/maker-bundle": "^1.48", // v1.48.0
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/stopwatch": "6.2.*", // v6.2.0
"symfony/web-profiler-bundle": "6.2.*", // v6.2.4
"zenstruck/foundry": "^1.26" // v1.26.0
}
}
11 Comments
Hi
when I type the following url: https://localhost:8000/api/docs.json in my browser I get the following error:
"title": "An error occurred",
"detail": "Format \"json\" is not supported",
could you help me please ?
That's because your api_platform.yaml doesn't contain format for json
you should add accept method
You can totally go fancy on the formats:
https://api-platform.com/docs/core/content-negotiation/#configuring-formats-globally
Hey @Nizar
If you remove the
.jsonpart does it work? I believe the main docs route does not support file extensions (but the API endpoints do)Cheers!
Hi Ryan,
I have an issue. I'm using mysql instead of postgresql (created a docker standard mysql 8 container from mysql:latest).
I was able to create the entity with the maker bundle, the migration, create the database (./bin/console doctrine:database:create) and execute the migration using CLI commands (./bin/console doctrine:migrations:migrate). The database was created and the tables as well.
All steps went successfully until I tried to submit a post request from the https://127.0.0.1:8000/api. I get the following error:
The problem is that for some reason it is trying to query a database named root, when in fact the database that was earlier created is called app.
In my .env file I have:
Any thoughts on this one?
Thanks,
Radu
Hey Radu!
Hmm. Do you have a
docker-compose.ymlfile? If you do and you have Docker running AND you have a container calleddatabase, then when you access the site, thesymfonybinary is overriding theDATABASE_URLenv var and setting it to point at that Docker container. If you're setting up your database locally (without Docker), just don't bother starting Docker and delete thedocker-compose.ymlfile entirely (or at least the matching service).If my guess is incorrect, let me know!
Cheers!
Hey @weaverryan,
Thanks for the quick reply! You were indeed correct! I've recreated my local container after renaming the database service in the docker-compose.yml file to my_app_database and the issue went away! :)
Cheers,
Radu
Hi,
Why api platform now gives duplicate properties from hydra docs?
For example, my expected JSON POST input looks like this:
instead of this:
I've tried setting up symfony and api platform over and over again, generating the entity via maker bundle, the same things happen.
Thanks in advance!
Hey @Zhivko
That's odd. If you look closely the repeated fields are in snake and camel case. I wonder if you may have both fields in your API resource, or for some reason, ApiPlatform is using both conventions to serialize your resources. I'd guess this is a misconfiguration of ApiPlatform
Cheers!
Hi @MolloKhan ,
Thanks for the answer.
Still not sure how to configure API Platform to avoid this duplication?
Here is my ApiResource enabled Symfony Entity class:
As you can see, nothing special, normally created Entity via the Maker bundle.
To me, it seems like API Platform serializes the get methods as well, but why?
Regards,
Zhivko
That's interesting. It could be a bug on ApiPlatform but I'm not sure. I believe the problem happens because you're mixing naming conventions (snake case and camel case). I think the easiest solution would be to stick to one convention, or you can use serialization groups to choose what fields to process
More info here: https://api-platform.com/docs/core/serialization/
Cheers!
"Houston: no signs of life"
Start the conversation!