This is a REST API built with Symfony and API Platform for managing fruits.
http://127.0.0.1:8000/api
GET /api/fruits
Returns a list of all fruits.
Response:
{
  "@context": "/api/contexts/Fruit",
  "@id": "/api/fruits",
  "@type": "Collection",
  "totalItems": 20,
  "member": [
    {
      "@id": "/api/fruits/1",
      "@type": "Fruit",
      "id": 1,
      "name": "Apple"
    }
  ]
}GET /api/fruits/{id}
Returns a specific fruit by ID.
Response:
{
  "@context": "/api/contexts/Fruit",
  "@id": "/api/fruits/1",
  "@type": "Fruit",
  "id": 1,
  "name": "Apple"
}POST /api/fruits
Creates a new fruit.
Headers:
Content-Type: application/ld+json
Request Body:
{
  "name": "Dragon Fruit"
}Response (201 Created):
{
  "@context": "/api/contexts/Fruit",
  "@id": "/api/fruits/21",
  "@type": "Fruit",
  "id": 21,
  "name": "Dragon Fruit"
}PUT /api/fruits/{id}
Updates a fruit completely.
Headers:
Content-Type: application/ld+json
Request Body:
{
  "name": "Updated Dragon Fruit"
}Response (200 OK):
{
  "@context": "/api/contexts/Fruit",
  "@id": "/api/fruits/21",
  "@type": "Fruit",
  "id": 21,
  "name": "Updated Dragon Fruit"
}PATCH /api/fruits/{id}
Partially updates a fruit.
Headers:
Content-Type: application/merge-patch+json
Request Body:
{
  "name": "Partially Updated Dragon Fruit"
}DELETE /api/fruits/{id}
Deletes a fruit.
Response (204 No Content)
GET /api/fruits/search?q={query}
Search for fruits by name (case-insensitive, partial match).
Example:
curl -X GET "http://127.0.0.1:8000/api/fruits/search?q=apple"Response:
[
  {
    "id": 1,
    "name": "Apple"
  },
  {
    "id": 6,
    "name": "Pineapple"
  }
]- name: Required, minimum 2 characters, maximum 255 characters
 
{
  "error": "Validation failed",
  "violations": {
    "name": "Fruit name cannot be blank"
  }
}{
  "error": "Fruit not found"
}{
  "@context": "/api/contexts/Error",
  "@type": "Error",
  "title": "An error occurred",
  "detail": "The content-type \"application/json\" is not supported. Supported MIME types are \"application/ld+json\".",
  "status": 415
}curl -X GET http://127.0.0.1:8000/api/fruitscurl -X GET http://127.0.0.1:8000/api/fruits/1curl -X POST http://127.0.0.1:8000/api/fruits \
  -H "Content-Type: application/ld+json" \
  -d '{"name":"Mango"}'curl -X PUT http://127.0.0.1:8000/api/fruits/1 \
  -H "Content-Type: application/ld+json" \
  -d '{"name":"Green Apple"}'curl -X DELETE http://127.0.0.1:8000/api/fruits/1curl -X GET "http://127.0.0.1:8000/api/fruits/search?q=berry"- Install dependencies:
 
composer install- Set up the database:
 
php bin/console doctrine:migrations:migrate- Load sample data:
 
php bin/console doctrine:fixtures:load- Start the server:
 
symfony serve- Access the API documentation at: 
http://127.0.0.1:8000/api 
- ✅ Full CRUD operations (Create, Read, Update, Delete)
 - ✅ Input validation with detailed error messages
 - ✅ JSON-LD format support (API Platform standard)
 - ✅ Search functionality
 - ✅ Proper HTTP status codes
 - ✅ Serialization groups for clean API responses
 - ✅ Sample data fixtures for testing
 - ✅ Both API Platform automatic endpoints and custom controller endpoints
 
This API uses API Platform, which provides:
- Automatic API documentation at 
/api - JSON-LD format support
 - Hydra vocabulary for API discoverability
 - OpenAPI/Swagger documentation
 - Automatic content negotiation
 
You can access the interactive API documentation by visiting http://127.0.0.1:8000/api in your browser.