Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine
This tutorial has a new version, check it out!

API Platform Installation!

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Yo friends! It's time to talk about... drum roll... how to bake a delicious cake that looks like an Oreo. Wait... ah! Wrong tutorial. It's time to talk about API Platform... so fun, it's almost as delicious as a cake shaped like an Oreo.

API Platform is crushing it these days. I feel like everywhere I turn, someone is raving about it! Its lead developer - Kévin Dunglas - is a core contributor of Symfony, super nice guy and is absolutely pushing the boundaries of what API's can do. We're going to see that first-hand. He was also nice enough to guide us on this tutorial!

Modern APIs are Hard. API Platform is not

If you only need to build a few API endpoints just to support some JavaScript, you might be thinking:

What's the big deal? Returning some JSON here and there is already pretty easy!

I've had this same opinion for awhile. But little-by-little, I think this is becoming less and less true. Just like how frameworks were born when web apps became more and more complex, tools like API Platform have been created because the same things is currently happening with APIs.

These days, API's are more than just returning JSON: it's about being able to serialize and deserialize your models consistently, maybe into multiple formats, like JSON or XML, but also JSON-LD or HAL JSON. Then there's hypermedia, linked data, status codes, error formats, documentation - including API spec documentation that can power Swagger. Then there's security, CORS, access control and other important features like pagination, filtering, validation, content-type negotiation, GraphQL... and... honestly, I could keep going.

This is why API Platform exists: to allow us to build killer APIs and love the process! Oh, and that big list of stuff I just mentioned that an API needs? API Platform comes with all of it. And it's not just for building a huge API. It really is the perfect tool, even if you only need a few endpoints to power your own JavaScript.

API Platform Distribution

So let's do this! API Platform is an independent PHP library that's built on top of the Symfony components. You don't need to use it from inside a Symfony app, but, as you can see here, that's how they recommend using it, which is great for us.

If you follow their docs, they have their own API Platform distribution: a custom directory structure with a bunch of stuff: one directory for your Symfony-powered API, another for your JavaScript frontend, another for an admin frontend all wired together with Docker! Woh! It can feel a bit "big" to start with, but you get all of the features out-of-the-box... even more than I just described. If that sounds awesome, you can totally use that.

But we're going to do something different: we're going to install API Platform as a bundle into a normal, traditional Symfony app. It makes learning API Platform a bit easier. Once you're confident, for your project, you can do it this same way or jump in and use the official distribution. Like I said, it's super powerful.

Project Setup

Anyways, to become the API hero that we all need, you should totally code along with me by downloading the course code from this page. After you unzip it, you'll find a start/ directory inside with the same code that you see here... which is actually just a new Symfony 4.2 skeleton project: there is nothing special installed or configured yet. Follow the README.md file for the setup instructions.

The last step will be to open a terminal, move into the project and start the Symfony server with:

symfony serve -d

This uses the symfony executable - an awesome little dev tool that you can get at https://symfony.com/download. This starts a web server on port 8000 that runs in the background. Which means that we can find our browser, head to localhost:8000 and see... well, basically nothing! Just the nice welcome page you see in an empty Symfony app.

Installing API Platform

Now that we have our empty Symfony app, how can we install API Platform? Oh, it's so awesome. Find your terminal and run:

composer require api:1.2.0

That's it. You'll notice that this is installing something called api-platform/api-pack. If you remember from our Symfony series, a "pack" is sort of a "fake" library that helps install several thing at once.

Heck, you can see this at https://github.com/api-platform/api-pack: it's a single composer.json file that requires several libraries, like Doctrine, a CORS bundle that we'll talk about later, annotations, API Platform itself and a few parts of Symfony, like the validation system, security component and even twig, which is used to generate some really cool documentation that we'll see in a minute.

But, there's nothing that interesting yet: just API Platform and some standard Symfony packages.

Back in the terminal, it's done! And has some details on how to get started. A few recipes also ran that gave us some config files. Before we do anything else, go back to the browser and head to https://localhost:8000/api to see... woh! We have API documentation! Well, we don't even have any API yet... so there's nothing here. But this is going to be a huge, free feature you get with API Platform: as we build our API, this page will automatically update.

Let's see that next by creating and exposing our first API Resource.

Leave a comment!

122
Login or Register to join the conversation
Ajie62 Avatar

Hey, thank you for this course. I think API Platform is great! I've been learning it for days now and I can't wait to see what you're going to teach us here. Keep up the good work, that's fantastic!

4 Reply

Thanks Ajie62 :)

Reply
excentrist Avatar
excentrist Avatar excentrist | posted 8 months ago

For anyone struggling with switching PHP versions: https://github.com/shivammathur/homebrew-php

2 Reply

Hi there!

Just started tutorial and got an error while installing the project.

Cache clear fail :-(

!! PHP Fatal error: Could not check compatibility between Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\LazyLoadingValueHolderGenerator::generate(ReflectionClass $originalClass, Zend\Code\Generator\ClassGenerator $classGenerator) and ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator::generate(ReflectionClass $originalClass, Laminas\Code\Generator\ClassGenerator $classGenerator), because class Zend\Code\Generator\ClassGenerator is not available in /home/atournayre/PhpstormProjects/code-api-platform/start/vendor/symfony/proxy-manager-bridge/LazyProxy/PhpDumper/LazyLoadingValueHolderGenerator.php on line 33
!!
!! In LazyLoadingValueHolderGenerator.php line 33:
!!
!! Compile Error: Could not check compatibility between Symfony\Bridge\ProxyMa
!! nager\LazyProxy\PhpDumper\LazyLoadingValueHolderGenerator::generate(Reflect
!! ionClass $originalClass, Zend\Code\Generator\ClassGenerator $classGenerator
!! ) and ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator::generate
!! (ReflectionClass $originalClass, Laminas\Code\Generator\ClassGenerator $cla
!! ssGenerator), because class Zend\Code\Generator\ClassGenerator is not avail
!! able

More about this error here : https://github.com/atournay...

I didn't manage to find a solution to this problem.

Anyone can help me solving this ?

Thanks!

2 Reply

I manage to make it work using : composer require api-platform/api-pack "1.2.0"

Thanks to finish folder in the course code.
Dependencies update is a very big problem in tutorials! (already talked about that with Ryan)

2 Reply

Hey atournayre!

This definitely sounds like a problem :). We have a new course "continuous integration" system (we just finished v1 2 days ago) - it sounds like we need to hook this course up to that and see what's going on.

Cheers!

2 Reply
ling Avatar

Hi Ryan, is this new course finished yet? Also, like Aurélien I stumbled upon lots of compatibility errors while doing this tutorial, which made me temporarily gave up, trying to gain more symfony experience elsewhere. But it would be nice if all those api-platforms tutorials would be ported to symfony 6. Any plans to do that? Thanks for the good work anyway.

Reply

Hey Pierre!

Yes, this course is finished. And, it should work just fine.... if you're using OUR code with our Symfony version. So, indeed, if you try to apply this to a Symfony 6 project, there will be some changes (not really much related to API Platform itself, but things more related to Symfony). We will upgrade these tutorials... but I'm not sure when. I need to check with the API Platform team to see what their roadmap is (so we don't upgrade these tutorials... only for them to release some big features right after!).

In the mean time, if you have some compat errors, we can definitely help debug those. Sorry I can't give a better answer!

1 Reply
amcastror Avatar
amcastror Avatar amcastror | posted 3 months ago

For all of us struggling with an empty spec "No operations defined in spec!" using php 8 attributes, there's a compatibility layer that needs to be disabled:

api_platform:
      metadata_backward_compatibility_layer: false

Source: https://github.com/api-platform/core/issues/4485#issuecomment-933448396

1 Reply
NilsJohan Avatar
NilsJohan Avatar NilsJohan | posted 8 months ago

Why can't you put up an tutorial, that everybody can follow? I'm really disappointed! This is legacy code with a PHP Version that was used 3 or more years ago. How can I get this tutorial working when composer doesn't support PHP 7.1.3 anymore and my local installation doesn't support PHP 7.1.3. This stuff is hard enough to learn and you are putting real big stones on the rough way up to learn Symfony.
I must assume, that this is only made for an elite group but not fro normal folks like me. Shame on you! Hopefully I'm wrong.

Reply

Hi NilsJohan!

Really sorry about the trouble - that’s not the experience we want :/. The code behind this tutorial is old. Fortunately, I’m working on writing a new version right now - we were waiting for ApiPlatform 3 to be released (it did a few months ago), but turning around and getting the tutorial out is never as fast as I’d like.

Anyways, sorry for the frustration - understandable! My hope is that in a few weeks, we’ll have a fresh version of these ApiPlatform tutorials releasing.

Cheers!

Reply
zazou Avatar
zazou Avatar zazou | posted 8 months ago | edited

Hi, i have a big problem on this tutorial : i do it on a mac and everything work, but today im on my personal pc at home, its a Windows pc, i have PHP 7.3, 7.4 a,d 8.1. Since today, it working but now i have a problem that i dont understand : when i install api with composer require api:1.2.0, when i try to refresh the main page or just go to /api, symfony say me:

syntax error, unexpected token "match"

When i see my composer.json:

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.1.3",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "api-platform/core": "^2.1",
        "composer/package-versions-deprecated": "^1.11",
        "doctrine/annotations": "^1.0",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/orm": "^2.4.5",
        "nelmio/cors-bundle": "^1.5",
        "phpdocumentor/reflection-docblock": "^3.0 || ^4.0",
        "symfony/asset": "4.2.*|4.3.*",
        "symfony/console": "4.2.*",
        "symfony/dotenv": "4.2.*",
        "symfony/expression-language": "4.2.*|4.3.*",
        "symfony/flex": "^1.1",
        "symfony/framework-bundle": "4.2.*",
        "symfony/security-bundle": "4.2.*|4.3.*",
        "symfony/twig-bundle": "4.2.*|4.3.*",
        "symfony/validator": "4.2.*|4.3.*",
        "symfony/yaml": "4.2.*"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true,
        "platform": {},
        "allow-plugins": {
            "symfony/flex": true
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "4.2.*|4.3.*"
        }
    }
}

I dont understand this error, i see match is a php 8 function but i dont do anything more today on my pc than yesterday on my work mac.
Maybe i should install a specific version of api platform core ?
Someone have the solution please ?

Reply

Hey Zazou,

Yes, match is the new PHP 8 syntax, see https://www.php.net/manual/en/control-structures.match.php - it seems like somewhere in your code or in the code of your dependencies it's used. Please, double-check the version of your PHP installed on Windows, are you on PHP 8? Because it seems like you have a lower version of PHP there. Then, you need to upgrade your PHP version first and the project should work fine. I bet you had PHP 8 on Mac but PHP 7 on Windows, and so it makes sense that dependencies installed on Mac does not work on Windows because of the lower version (they were installed for PHP 8).

Or if your project should work on a lower version, e.g. PHP 7.1 - you should explicitly said this in your composer.json via:

{
    "config": {
        "platform": {
            "php": "7.1.3"
        }
    }
}

Ideally, in config.platform.php use the same PHP version you're using on production for this project. After you added that config.platform.php - you will also need to update dependencies with composer update to fetch Composer dependencies for the specified PHP version.

Cheers!

Reply
zazou Avatar
zazou Avatar zazou | Victor | posted 8 months ago | edited

On my PC i have 3 versions of PHP : 7.3, 7.4 and 8. For this tuto, i declare on my windows environnement variable to use the 7.4 version of php. when i run a terminal on windows and run php -v, it's the good version of php 7.4.
I use xamp for mysql and apache and it work on php 8.

I try to add config platform php 7.1.3 in composer.json, run composer update and i have the same error again :(

Reply

Hey Zazou,

The easiest way for you would be to use PHP 8 I suppose :) I bet the project will work fine on PHP 8 for you, but it would mean that you will have problems with running it on PHP 7 unless you fixed it. In theory, you can just bump your PHP version in the composer.json to PHP ^8.

But if you really need to run the project on legacy PHP versions, and specifically on the 7.1.3 as you mention in your composer.json - then yeah, you need to set the config.platform.php version to 7.1.3 as you did, and also update dependencies with composer update - please make sure you do not have any errors during that command executing, the command should be executed without any errors. Then clear the cache just in case and check again - if you still see the same issue about match - most probably you have this match use in your code, not in the third-party libraries you have installed. So, you will need to find the place where you use that match in your code and rewrite it with a legacy PHP code.

I hope this helps!

Cheers!

Reply
Emanuele-P Avatar
Emanuele-P Avatar Emanuele-P | posted 10 months ago

Hallo @weaverryan, we have develop an app in symfony 6.1 and apiplatform 2.6, we have been successfully moved to version 2.7.2 with the flag to be ready for 3
but when i try to go further ( with version 3 ) i find out the a lot of changes happen in the @context, i could not find any proper info about it ( not in the docs at least), is it possible to have more info about it?

Reply

Hey Emanuele-P!

we have been successfully moved to version 2.7.2 with the flag to be ready for 3

Nice!

but when i try to go further ( with version 3 ) i find out the a lot of changes happen in the @context, i could not find any proper info about it ( not in the docs at least), is it possible to have more info about it?

We're' going to make a tutorial for API Platform 3 before the year is over - it's one of my top priorities. I'll be sure to mention, in that tutorial, as many differences as I can before 2 and 3 to help ease the transition. So, it's coming!

Cheers!

Reply
Ninsky Avatar

Is it possible to disable SwaggerUI on production when env=prod in .env?

Reply

Hey Ninsky!

I believe you could do something like:

when@prod:
    api_platform:
        enable_swagger: false
        enable_swagger_ui: false

I believe the difference between those two options is that the UI prevents the HTML version of the page being loaded, but enable_swagger controls if you could see the JSON version of the "open api" docs.

Let me know if that helps :).

Cheers!

Reply
Ninsky Avatar

Hello Ryan

Thanks for your help! Will give it a try. Also found the following params which I will test:

when@prod:
  api_platform:
    enable_docs: false
    enable_entrypoint: false

Have a nice day
Ninsky

Reply

Hello! Many thanks for this tutorial!

My API bundle works perfectly between my Angular frontend part and my Symfony backend part without doing Auth to my app. After adding the auth configration to my symfony app I can't post the data from angular anymore. Here is the message that i found in the inspecter:

Access to XMLHttpRequest at 'https://localhost:8000/api/link' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.```



I am also using NelmioCorsBundle to avoid this problem but it doesn't work: 


nelmio_cors:
    defaults:
        allow_credentials: false
        allow_origin: []
        allow_headers: []
        allow_methods: []
        expose_headers: []
        max_age: 0
        hosts: []
        origin_regex: false
        forced_allow_origin_value: ~

    paths:
        '^/api/':
            allow_origin: ['*']
            allow_headers: ['X-Custom-Auth']
            allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
            max_age: 3600

        '^/':
            origin_regex: true
            allow_origin: ['^http://localhost:[0-9]+']
            allow_headers: ['X-Custom-Auth']
            allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
            max_age: 3600
            hosts: ['^api\.']```

I also disable the security in Chrome and get this error
ERR_CERT_AUTHORITY_INVALID

Many thansk for your help!! Really appreciate your support :)

Reply

Hey Lubna

It seems like you're doing the request to a non https endpoint. Try updating your Nelmio config - change the allow_origin key to allow HTTPS

Cheers!

Reply
Benoit-L Avatar
Benoit-L Avatar Benoit-L | posted 1 year ago

Hi there, I have uploaded the directory start and run the following : symfony serve -d but I have got the following error message : Cette page n’est pas disponible pour le moment127.0.0.1 ne peut actuellement pas traiter cette demande.
HTTP ERROR 500.

I have solved the problem doing an composer update.

Reply

Hey Benoit L.!

Thanks for sharing your solution :). I'm not sure what happened, but the course does require a composer update if you're using PHP 8. We don't update the course download code because we want it to match what you see in the video exactly.

Cheers!

Reply
Benoit-L Avatar

In fact, I'm facing this problem again this morning. And my version of PHP is 7.4.13.
I have created the bookshop-api proposed on the https://api-platform.com/do... and when I run the same command it works with the command symfony serve -d. So the only 2 differences I see is that when I have created the project following the instructions of api-Platform we start by running the instructions "composer create-project symfony/skeleton bookshop-api " and after that we run the instruction "composer require api". I could try to create the start project with those instructions then importing the files inside the project.
What do you think ?

Reply

Hey @Benoit!

Apologies for the slow reply! Ok, let's see:

> Is is normal that there is this file htaccess with "Deny from all"

What htaccess file are you referring to? I don't see any htaccess file when I download the course code from this page, and I wouldn't expect to see any .htaccess files. Do you see one somewhere?

> could try to create the start project with those instructions then importing the files inside the project.

You could certainly try that! Though, I *would* love to figure out the underlying problem that you're having :).

Cheers!

Reply
Benoit-L Avatar

I'm creating the project inside Php Storme and I see this file. I would like to add a screen shot but I am not sure how to do it.
This is the message that I get when I run symfony server:start : [Web Server ] Mar 26 20:32:57 |ERROR | SERVER GET (500) / ip="127.0.0.1".
I see this message in the log as well : [Web Server ] [26-Mar-2022 19:32:57 UTC] PHP Fatal error: require(): Failed opening required 'C:\wamp64\www\api-platform\start/vendor/autoload.php'
And when I run the same command on the finish project I have the same error which seems to me weird.

Reply
Benoit-L Avatar

concerning the .htaccess file it is in the cache folder both in the start and the finish projects. I don't have the image icon to share with you the screenshot otherwise you would have no choice than to believe me :)

-1 Reply

Hey Benoit L.!

Sorry for the slow reply!

[Web Server ] [26-Mar-2022 19:32:57 UTC] PHP Fatal error: require(): Failed opening required 'C:\wamp64\www\api-platform\start/vendor/autoload.php'

Hmm. This looks like you should run composer install. Did you run that? There is a README.md file in each directory (start or finish) with the commands you'll need to get everything up and running.

concerning the .htaccess file it is in the cache folder both in the start and the finish projects

Ah, the cache/ folder - var/cache right? Interesting. When I download the course code from this page, there is NO var/ directory at all (which is correct: this file is created on demand by Symfony whenever it's needed). But, it doesn't really matter: the cache directory isn't meant to be publicly accessible anyways, so an .htaccess in that directory wouldn't cause any problems :).

Cheers!

Reply
Benoit-L Avatar

Yes, sorry for this. I've got a new error now when I run:

$ php bin/console doctrine:migrations:migrate

Attempted to call an undefined method named "getAllRawData" of class "Composer\InstalledVersions"

Reply

Hey Benoit L.!

Sorry for the slow reply! Hmm. Try upgrading Composer. I'm seeing that this getAllRawData() method, which lives in Composer, was introduced in version 2.0.14. That's my first guess: it's a very odd error :/.

Cheers!

1 Reply
davidmintz Avatar
davidmintz Avatar davidmintz | posted 1 year ago | edited

My machine has php8.1 installed and composer install doesn't like it. I tried hacking the PHP version string in composer.json like so:

"php": "^7.1.3 || 8.*",

and then I tried composer update with the result


Your requirements could not be resolved to an installable set of packages.


  Problem 1
    - symfony/console[v4.2.0, ..., v4.2.12] require php ^7.1.3 -> your php version (8.1.1) does not satisfy that requirement.
    - Root composer.json requires symfony/console 4.2.* -> satisfiable by symfony/console[v4.2.0, ..., v4.2.12].

What solution would you recommend? Thanks.

Reply

Hey Elliott,

We're sorry about that. Unfortunately, this course isn't compatible with PHP 8 out of the box, and we warn about it with a tooltip when you download the course code. We do recommend to run the course project code on PHP 7.x to be able execute "composer install" command successfully. But if you do want to run it on PHP 8 - you would need to update the dependencies that may lead to more required steps to make the project code to work on PHP 8.

The change you made in the composer.json is the first step. But looks like this course is based on Symfony 4.2, and the latest version 4.2.12 does not support PHP 8 either, see: https://github.com/symfony/...

So, to be able to run this project on PHP 8 - you will need to upgrade Symfony to 4.4 at least first, that may require more work. If you want - you can go this way, or fallback to PHP 7.x.

I hope this helps!

Cheers!

Reply
Serkan Avatar
Serkan Avatar Serkan | posted 1 year ago | edited

Hi;
I want to use docker database in this tutorial. I created a docker-compose file by maker command. But while creating entity for CheeseListing I got an error like Invalid argument supplied for foreach(). I couldn't crate an entity.

Reply

Hey Serkan,

It's difficult to tell you what's wrong exactly. Please, try to debug things yourself. Error message will give you some hints about what file, what line. Open that file and try to debug the argument that is supplied to that foreach - you can use "dd($variableName)" to dump the variable. Then, try to debug why you're passing there not an array and where. Then, it should be easy to fix.

I hope this helps!

Cheers!

Reply
Covi A. Avatar
Covi A. Avatar Covi A. | posted 2 years ago

thanks for your answer, i solved it.

Reply
Covi A. Avatar
Covi A. Avatar Covi A. | posted 2 years ago

Hi
i am trying to install doctrine for work with docker but when i install orm (composer require orm) then orm install successfully but command prompt not work correctly. and for this reason i could not create database.
when i am try this command php bin/console then it's show me this error

An option named "connection" already exists.

can you help me about this problem

Reply

Hey Covi A.

If you're using Docker, first double-check that your MySql instance it's up and running, then, you'll have to run symfony commands through the Symfony CLI symfony console doctrine:database:create, so it can automatically inject the right environment variables, for example, the database URL coming from your Docker instance
Here you can download the Symfony CLI https://symfony.com/download

Cheers!

Reply
Dennis B. Avatar
Dennis B. Avatar Dennis B. | posted 2 years ago

I've set up the project using Symfony 5.2.5 and API Platform 2.6.3.
When I try to access "http://localhost:8000/api" I am presented an Exception telling me "Unable to generate a URL for the named route "api_doc" as such route does not exist."
Is there anything I can do to get the thing to work?

Thanks in advance.

Reply

Hey Dennis B.

Did you notice if a "recipe" was installed when you installed ApiPlatform? You should have gotten this file config/routes/api_platform.yaml
Cheers!

Reply
Dennis B. Avatar
Dennis B. Avatar Dennis B. | MolloKhan | posted 2 years ago | edited

Hi MolloKhan !

Yes, that file I have. And it contains:
`api_platform:

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

I believe you checked the wrong file. I'm talking about the file inside config/routes. Its content should be like this one https://github.com/symfony/recipes/blob/master/api-platform/core/2.1/config/routes/api_platform.yaml

Cheers!

Reply
Dennis B. Avatar

Ah, okay. Sorry.
Also this file I have and it looks exactly like the one on github, you did link.

Reply

Hmm, that's really weird. What's the output of `bin/console debug:router`? For some reason it's not loading the ApiPlatform route

Reply
Dennis B. Avatar
Dennis B. Avatar Dennis B. | MolloKhan | posted 2 years ago | edited

The output doesn't show any route.
`➜ api-platform git:(master) ✗ bin/console debug:router


Name Method Scheme Host Path


➜ api-platform git:(master) ✗`

"api-platform" is also the folder's name of my project. But I cannot imagine that this would be a problem.

Reply
Dennis B. Avatar

Well, since I had not really a project so far, I decided to throw everything away and gave it a new try.

So, I copied the stuff from the tutorial's "start" directory, adjusted the packages' version numbers to 5.x, reinstalled the packages and now it works fine.

Reply

Hey Dennis B.

Sorry for my slow reply. I believe you had a configuration problem. Your routes weren't being loaded for some reason. I'm glad to hear that your project it's set up now. Let us know if you run into more troubles

Cheers!

Reply
Jakub R. Avatar

Hi guys, thanks for the great work. I am having the same problem, but I have a larger project that I cannot afford to rewrite. Any other ideas, why it is not loading the routes? I have tried a new project and it work with that. I have also for testing purposes removed my access_control rules (left only - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY })

I am using in some cases groups and serializer and json response to make some rest endpoints. Can that collide?

Reply
Jakub R. Avatar

Nevermind. Composer install was the trick. It runs now. My bad :)

1 Reply
Miky Avatar

Sorry if you marked me fist as spam... too much text from console... but question is simple...
Why composer install wont run on php 8 version but only on 7.1.3+ version max to 7.4 version
What do i need to setup ?

From console i did 14 problems with similar context
Problem 1 ....

- Root composer.json requires php ^7.1.3 but your php version (8.0.2) does not satisfy that requirement.

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

This tutorial works great for Symfony 5 and API Platform 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.17.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
    }
}
userVoice