The First API Resource: Hello World
The First API Resource: Hello World
~13 Min. Lesezeit Zuletzt aktualisiert am August 8, 2026
Time for your FIRST real result: a minimal, working API resource, with NO database, NO Doctrine – JUST to experience the core principle before chapter 9 continues systematically.
An ApiResource WITHOUT a Doctrine entity
API Platform does NOT strictly require a Doctrine entity – a SIMPLE PHP class with the #[ApiResource] attribute is already enough:
<?php
declare(strict_types=1);
namespace App\ApiResource;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
#[ApiResource(
operations: [
new Get(
uriTemplate: '/greeting',
provider: [self::class, 'provideGreeting'],
),
],
)]
class Greeting
{
public string $message = '';
public static function provideGreeting(): self
{
$greeting = new self();
$greeting->message = 'Hello from the Task Manager!';
return $greeting;
}
}provider specifies WHICH method supplies the data for this operation – the "state provider" concept, which chapters 57-58 explore SYSTEMATICALLY. For NOW, it's enough that it's a static method returning an instance of the class.
Testing the resource
curl -k https://localhost/api/greeting{
"@context": "/api/contexts/Greeting",
"@id": "/api/greeting",
"@type": "Greeting",
"message": "Hello from the Task Manager!"
}The @context/@id/@type fields come from JSON-LD (mentioned in chapter 3) – additional, semantic metadata that API Platform includes BY DEFAULT. For our React frontend, from chapter 73 on, we'll usually request the simpler json format, which OMITS these fields.
No cache issue: configuration changes take effect immediately
EXACTLY as explained in chapter 4 of the Symfony course: in the development environment (the default for this distribution), code AND configuration changes are detected IMMEDIATELY – no manual cache:clear needed to see the new resource.
What comes next
Tipp: This Greeting resource was deliberately MINIMAL to show the core principle – from chapter 9 on, we work with REAL Doctrine entities (Project, Task, ...), for which API Platform FULLY AUTOMATICALLY generates SIX operations (instead of just ONE here), without us writing a provider ourselves.