I am a beginner in Sylius and i'm trying to use the API, but it does not work. Each result is "404 Page not found".
Steps :
- Creating an apache2 vhost (hostname : myproject.local
- Installing Sylius (1.10) with official documentation (Project Database Front compilation)
- Adding some content with the admin panel
- Creating new customer from Front Office
Everything is OK but when i'm trying to create a user with the API, the response is the "Route not found (404 Not Found)" HTML page. (This is the very first API call from the official documentation : Sylius API doc)
That is my OS details :
Distributor ID: Ubuntu
Description: Ubuntu 21.04
Release: 21.04
Codename: hirsute
I am using Apache2 and MySQL :
Server version: Apache/2.4.46 (Ubuntu)
Server built: 2021-09-28T10:57:42
mysql Ver 8.0.27-0ubuntu0.21.04.1 for Linux on x86_64 ((Ubuntu))
When i use the command :
php bin/console debug:router api
I can see 189 results, i tried some, for example :
-------------- ---------------------------------------------------------
| Property | Value |
-------------- ---------------------------------------------------------
| Route Name | api_doc |
| Path | /api/v2/docs.{_format} |
| Path Regex | {^/api/v2/docs(?:\.(?P<_format>[^/] ))?$}sD |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | ANY |
| Requirements | NO CUSTOM |
| Class | Symfony\Component\Routing\Route |
| Defaults | _api_respond: true |
| | _controller: api_platform.action.documentation() |
| | _format: |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
-------------- ---------------------------------------------------------
URL : http://myproject.local/api/v2/docs, but the result is the same
Did i miss something ?
CodePudding user response:
Well, i forgot to active the API :
As the documentation says, "The new unified Sylius API is still under development" so this feature needs to be enabled.
Edit config/packages/_sylius.yaml to add :
sylius_api:
enabled: true
Now the API is activated, the routes no longer respond 404.
Last thing, before you can actually use the API you need to generate a JWT key pair otherwise the API calls will return "Unable to create signed JWT from given configuration".
To do that, use the JWT package (Lexik Repository) :
php bin/console lexik:jwt:generate-keypair
Now everything is good you can use the API, enjoy :)