Chapters
27 Chapters
|
2:54:11
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
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!
Este tutorial funciona muy bien para Symfony 5 y la Plataforma API 2.5/2.6.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^2.1", // v2.4.3
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.2
"doctrine/doctrine-bundle": "^1.6", // 1.11.2
"doctrine/doctrine-migrations-bundle": "^2.0", // v2.0.0
"doctrine/orm": "^2.4.5", // v2.7.2
"nelmio/cors-bundle": "^1.5", // 1.5.5
"nesbot/carbon": "^2.17", // 2.19.2
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0", // 4.3.1
"symfony/asset": "4.2.*|4.3.*|4.4.*", // v4.3.11
"symfony/console": "4.2.*", // v4.2.12
"symfony/dotenv": "4.2.*", // v4.2.12
"symfony/expression-language": "4.2.*|4.3.*|4.4.*", // v4.3.11
"symfony/flex": "^1.1", // v1.21.6
"symfony/framework-bundle": "4.2.*", // v4.2.12
"symfony/security-bundle": "4.2.*|4.3.*", // v4.3.3
"symfony/twig-bundle": "4.2.*|4.3.*", // v4.2.12
"symfony/validator": "4.2.*|4.3.*", // v4.3.11
"symfony/yaml": "4.2.*" // v4.2.12
},
"require-dev": {
"symfony/maker-bundle": "^1.11", // v1.11.6
"symfony/stopwatch": "4.2.*|4.3.*", // v4.2.9
"symfony/web-profiler-bundle": "4.2.*|4.3.*" // v4.2.9
}
}
19 Comments
Hi , I got an error When I add .json or .jsonld to the URL: 'The requested resource /api/cheese_listings/1.json was not found on this server.'
Hey hanen
Can you double check that there is a CheeseListing record with an ID set to 1 on your database?
Cheers!
I use the curl command curl -X GET "http://localhost:8000/api/cheese_listings" -H "accept: application/ld+json"
{"@context":"\/api\/contexts\/CheeseListing","@id":"\/api\/cheese_listings","@type":"hydra:Collection","hydra:member":[{"@id":"\/api\/cheese_listings\/1","@type":"CheeseListing","id":1,"title":"eating blue cheese","description":"still... good","price":100,"createdAt":"2019-07-23T10:06:53+02:00","isPublished":true},
When Im using api/cheese_listings/1 I have the api interface with all availables resources but entrypoint like /api/cheese_listings/1.jsonld return 404 not found
Hey hanen!
Hmm, it could just be a little web server problem. What web server are you using? When some web-servers see a "." (e.g. 1.json) - they assume you're trying to access a physical file. And so, instead of executing the framework like normal, they 404 when they can't find that file. One fix / way to confirm this is to see if going to "/index.php/api/cheese_listing/1.json" works :).
Cheers!
oh awesome !! it works weaverryan thanks a lot :)))
Hi and many thanks for the informative and entertaining course! :) When I call entities via "/api/contexts/", e.g. "/api/contexts/CheeseListing", all attributes resp. getter/setters of the entity class are exposed. Is it possible to avoid this? Unfortunately, it is not enough to restrict an API resource via normalization and denormalization contexts. Because of the principle of information hiding I only want to expose those fields under "/api/contexts/" that can be used for the API operations. Thanks a lot! :)
Hey Yves
I recommend you to read about Serialization groups or you want watch this chapter https://symfonycasts.com/sc...
Basically, you define property by property if you want to make it readable and/or writeable
Cheers!
I've already looked for a solution on api-platform.com, but found nothing ...
Hi Diego, thanks for you answer! :) I've already tried serialization groups. This works very well for the read and write schemas of the API operations. There I only see what I annotate. What I was asking for is the type definition of "CheeseListing" under the @context path "/api/contexts/CheeseListing". In the example of this course, "createdAt" and "isPublished" are also visible there, although these methods don't have a serialization group in the entity class "CheeseListing.php". My question is: how can I completely avoid the publication of these class methods in the @context type documentation? They are not relevant for the API usage and reveal more about the internal implementation than you might want to reveal.
Ohh I wasn't aware of that. Hmm, maybe this chapter can help you https://symfonycasts.com/sc...
Ryan shows how you can modify the metadata of your endpoints, it requires some work but I think that's what you need
Cheers!
hi , there are framework with creates entities from web api external ?
How does doctrine do with mapping databases to entities :)
Hey Gustavo C.
I don't fully understand what you mean with "framework with creates entities from web api external". But what Doctrine does, in short, is to read some metadata from your entities that you define/write, and then convert it into SQL statements and execute them
Cheers!
Diego , como va , lo que digo si hay alguna funcion de symfony que pueda desde una REST API externa tomar todos los metodos (put , get , delete ..... ,etc) y volcarlos en entidades ? lo de doctrine lo digo ya que hay una funcion que permite( a la inversa de lo que me explicas ) de la base de datos obtener las entidades ya con todos sus metodos.
Hola Gustavo. La verdad desconosco si existe alguna libreria que te pueda ayudar a hacer lo que necesitas, a la mejor si dicha API soporta el formato json+ld, de esa forma podrias extraer/leer toda la metadata de los llamados y generar las entidades pero es algo que no he hecho antes. Si descubres algo interesante al respecto, escribenos!
Saludos!
Gracias Diego :)
What google chrome extension you added to display the JSON properly?
Hey Ronald V.
I'm not 100% sure of Ryan's extension but I'm using "Json Formatter" and it's really good. https://github.com/callumlo...
Cheers!
For me the link /api/context/CheeseListing goes back No route found for "GET /api/context/CheeseListing", it is rather this link /api/contexts/CheeseListing that works for me!
!!
Hey Souleyman
You are 100% right! Thanks for informing us - I already fixed it :)
Cheers!
"Houston: no signs of life"
Start the conversation!