### Install GraphQL Support (Composer Command) Source: https://api-platform.com/docs/symfony/index This command installs the necessary api-platform/graphql library to enable GraphQL support in an API Platform project. It uses Composer to manage dependencies. ```bash docker compose exec php composer require api-platform/graphql ``` -------------------------------- ### Start Built-in PHP Server with Symfony CLI Source: https://api-platform.com/docs/symfony/index Command to start the built-in PHP development server. This allows you to run and test your Symfony application locally. ```bash symfony serve ``` -------------------------------- ### Example Dummy Entity in PHP Source: https://api-platform.com/docs/symfony/index A basic entity definition in PHP for API Platform, demonstrating the use of Doctrine ORM for persistence. This is a placeholder entity. ```php id; } } ``` -------------------------------- ### Start API Platform Docker Services Source: https://api-platform.com/docs/symfony/index Starts all defined Docker services for the API Platform project in detached mode. The `--wait` flag ensures services are ready before proceeding. ```bash docker compose up --wait ``` -------------------------------- ### API Access and Documentation Source: https://api-platform.com/docs/symfony/index Details on how to access the API documentation and interact with the API after setup. ```APIDOC ## Accessing the API ### Description After setting up API Platform, the API will be accessible at the `/api/` path. The API documentation is available at `/docs/`. ### Method GET ### Endpoint `https://localhost/api/` `https://localhost/docs/` ### Query Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) The API documentation in OpenAPI format, rendered with Swagger UI. #### Response Example Swagger UI interface allowing interaction with API operations. ## Accessing Raw Data ### Description To access the raw data of resources, you can either set the appropriate `Accept` header or append the desired format as an extension to the resource URL. ### Method GET ### Endpoint `https://localhost/greetings` (uses `Accept` header) `https://localhost/greetings.jsonld` (appends `.jsonld` extension) ### Query Parameters None ### Request Body None ### Request Example ```http GET /greetings HTTP/1.1 Host: localhost Accept: application/ld+json ``` ### Response #### Success Response (200) Raw data of the requested resource in the specified format (e.g., JSON-LD). #### Response Example ```json { "@context": "/api/contexts/Greeting", "@id": "/api/greetings", "@type": "/api/greetings", "hydra:member": [ { "@id": "/api/greetings/1", "@type": "Greeting", "id": 1, "content": "Hello World!" } ], "hydra:totalItems": 1 } ``` ## Interacting with API Operations ### Description You can interact with API operations directly through the Swagger UI. This includes creating, retrieving, and deleting resources. ### Method POST, GET, DELETE ### Endpoint Examples provided for the `Greeting` resource: - POST `/greetings` - GET `/greetings/{id}` - DELETE `/greetings/{id}` ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the greeting resource. #### Query Parameters None #### Request Body For POST operation to create a Greeting: - **content** (string) - Required - The content of the greeting. ### Request Example **POST /greetings** ```json { "content": "New Greeting" } ``` **GET /greetings/{id}** (No request body, uses path parameter for ID) **DELETE /greetings/{id}** (No request body, uses path parameter for ID) ### Response #### Success Response (200/201) - **id** (integer) - The unique identifier of the greeting. - **content** (string) - The content of the greeting. #### Response Example **POST Response:** ```json { "@id": "/api/greetings/2", "@type": "Greeting", "id": 2, "content": "New Greeting" } ``` **GET Response:** ```json { "@id": "/api/greetings/2", "@type": "Greeting", "id": 2, "content": "New Greeting" } ``` **DELETE Response:** (Typically returns an empty body with a 204 No Content status, or a confirmation message.) ``` -------------------------------- ### Install API Platform Server Component Source: https://api-platform.com/docs/symfony/index Command to install the API Platform server component using the Symfony composer. This adds the necessary packages for API Platform functionality. ```bash symfony composer require api ``` -------------------------------- ### Create New Symfony Project with Symfony CLI Source: https://api-platform.com/docs/symfony/index Command to create a new Symfony project. This is the initial step for setting up a project using the Symfony CLI. ```bash symfony new bookshop-api ``` -------------------------------- ### Create Doctrine Database and Schema Source: https://api-platform.com/docs/symfony/index Commands to create the database and its schema using Doctrine, a popular ORM for PHP. These commands are essential for database-driven applications. ```bash symfony console doctrine:database:create symfony console doctrine:schema:create ``` -------------------------------- ### Entity Mapping with Doctrine ORM Attributes Source: https://api-platform.com/docs/symfony/index Demonstrates how to map PHP entities to database tables using Doctrine ORM attributes, as shown in the Book and Review entity examples. ```APIDOC ## Entity Mapping with Doctrine ORM Attributes This section illustrates how to define entities that can be persisted using Doctrine ORM. API Platform leverages these entities to provide read and write capabilities for your API resources. The examples below show the `Book` and `Review` entities mapped using Doctrine's attributes. ### Entity: Book This entity represents a book in the system. ```php reviews = new ArrayCollection(); } } ``` ### Entity: Review This entity represents a review for a book. ```php id; } } ``` ### Generating Entities with API Platform Support To generate Doctrine entities that are also API resources, you can use Symfony's MakerBundle: ```bash docker compose exec php bin/console make:entity --api-resource ``` ### Database Migrations After defining your entities, you need to generate and apply database migrations: ```bash docker compose exec php bin/console doctrine:migrations:diff docker compose exec php bin/console doctrine:migrations:migrate ``` ### API Request Example (POST Book) This is an example of a request body to create a new book resource. #### Request Body - **isbn** (string) - The ISBN of the book. - **title** (string) - Required - The title of the book. - **description** (string) - The description of the book. - **author** (string) - Required - The author of the book. #### Request Example ```json { "isbn": "9781782164104", "title": "Persistence in PHP with the Doctrine ORM", "description": "This book is designed for PHP developers and architects who want to modernize their skills through better understanding of Persistence and ORM.", "author": "Kévin Dunglas" } ``` ### API Response Example (POST Book) This is an example of a successful response after creating a new book resource. #### Success Response (201 Created) - **id** (integer) - The unique identifier of the book. - **isbn** (string | null) - The ISBN of the book. - **title** (string) - The title of the book. - **description** (string) - The description of the book. - **author** (string) - The author of the book. - **publicationDate** (string) - The publication date of the book (ISO 8601 format). - **reviews** (array) - An array of reviews associated with the book. #### Response Example ```json { "@context": "/contexts/Book", "@id": "/books/1", "@type": "Book", "id": 1, "isbn": "9781782164104", "title": "Persistence in PHP with the Doctrine ORM", "description": "This book is designed for PHP developers and architects who want to modernize their skills through better understanding of Persistence and ORM.", "author": "Kévin Dunglas", "publicationDate": "2023-10-27T10:00:00+00:00", "reviews": [] } ``` ``` -------------------------------- ### Install Testing Dependencies with Composer Source: https://api-platform.com/docs/symfony/testing Installs Foundry and Doctrine/DoctrineFixturesBundle using Composer for testing purposes. These are development dependencies. ```bash composer require --dev foundry orm-fixtures ``` -------------------------------- ### Install API Platform Test Client Dependencies Source: https://api-platform.com/docs/symfony/testing Installs the necessary packages, `symfony/browser-kit` and `symfony/http-client`, to enable the API Platform test client within your Symfony project. ```bash composer require symfony/browser-kit symfony/http-client ``` -------------------------------- ### Build Docker Images for API Platform Source: https://api-platform.com/docs/symfony/index Builds the Docker images for the API Platform project. It's recommended to use `--no-cache` to ensure a clean build. ```bash docker compose build --no-cache ``` -------------------------------- ### Install LexikJWTAuthenticationBundle Source: https://api-platform.com/docs/symfony/jwt Installs the LexikJWTAuthenticationBundle using Composer. This is the first step to enable JWT-based authentication in your Symfony API. ```bash composer require lexik/jwt-authentication-bundle ``` -------------------------------- ### Navigate to Symfony Project Directory Source: https://api-platform.com/docs/symfony/index Command to change the current directory to the newly created Symfony project. This is necessary to execute further project-specific commands. ```bash cd bookshop-api ``` -------------------------------- ### Book Resource API Source: https://api-platform.com/docs/symfony/index This section details the operations available for the Book resource, including creation, retrieval, and updates. ```APIDOC ## POST /api/books ### Description Creates a new book resource. ### Method POST ### Endpoint /api/books ### Request Body - **title** (string) - Required - The title of the book. - **publicationDate** (string) - Required - The publication date of the book (e.g., "2013-12-01"). ### Request Example ```json { "title": "The Great Gatsby", "publicationDate": "2013-12-01" } ``` ### Response #### Success Response (201 Created) - **@id** (string) - The IRI of the created book resource. - **@type** (string) - The type of the resource (e.g., "Book"). - **@context** (string) - The JSON-LD context. - **title** (string) - The title of the book. - **publicationDate** (string) - The publication date of the book. #### Response Example ```json { "@id": "/api/books/1", "@type": "Book", "@context": "/api/contexts/Book", "title": "The Great Gatsby", "publicationDate": "2013-12-01" } ``` ## GET /api/books ### Description Retrieves a collection of book resources. ### Method GET ### Endpoint /api/books ### Query Parameters - **page** (integer) - Optional - The page number for pagination. - **limit** (integer) - Optional - The number of items per page. ### Response #### Success Response (200 OK) - **@id** (string) - The IRI of the collection. - **@type** (string) - The type of the resource (e.g., "hydra:Collection"). - **hydra:member** (array) - An array of book resources. - **hydra:totalItems** (integer) - The total number of items in the collection. #### Response Example ```json { "@id": "/api/books", "@type": "hydra:Collection", "hydra:member": [ { "@id": "/api/books/1", "@type": "Book", "@context": "/api/contexts/Book", "title": "The Great Gatsby", "publicationDate": "2013-12-01" } ], "hydra:totalItems": 1 } ``` ## GET /api/books/{id} ### Description Retrieves a specific book resource by its ID. ### Method GET ### Endpoint /api/books/{id} #### Path Parameters - **id** (integer) - Required - The ID of the book to retrieve. ### Response #### Success Response (200 OK) - **@id** (string) - The IRI of the book resource. - **@type** (string) - The type of the resource (e.g., "Book"). - **@context** (string) - The JSON-LD context. - **title** (string) - The title of the book. - **publicationDate** (string) - The publication date of the book. #### Response Example ```json { "@id": "/api/books/1", "@type": "Book", "@context": "/api/contexts/Book", "title": "The Great Gatsby", "publicationDate": "2013-12-01" } ``` ## PATCH /api/books/{id} ### Description Updates a specific book resource partially. ### Method PATCH ### Endpoint /api/books/{id} #### Path Parameters - **id** (integer) - Required - The ID of the book to update. ### Request Body - **title** (string) - Optional - The new title of the book. - **publicationDate** (string) - Optional - The new publication date of the book. ### Request Example ```json { "title": "The Definitive Gatsby" } ``` ### Response #### Success Response (200 OK) - **@id** (string) - The IRI of the updated book resource. - **@type** (string) - The type of the resource (e.g., "Book"). - **@context** (string) - The JSON-LD context. - **title** (string) - The updated title of the book. - **publicationDate** (string) - The updated publication date of the book. #### Response Example ```json { "@id": "/api/books/1", "@type": "Book", "@context": "/api/contexts/Book", "title": "The Definitive Gatsby", "publicationDate": "2013-12-01" } ``` ## DELETE /api/books/{id} ### Description Deletes a specific book resource by its ID. ### Method DELETE ### Endpoint /api/books/{id} #### Path Parameters - **id** (integer) - Required - The ID of the book to delete. ### Response #### Success Response (204 No Content) ``` -------------------------------- ### Inspect Xdebug Installation Source: https://api-platform.com/docs/symfony/debugging Verifies the Xdebug installation within the API Platform Docker container. This command executes `php --version` inside the PHP service to display Xdebug version information, confirming it's installed and accessible. ```bash $ docker compose exec php \ php --version ``` -------------------------------- ### Follow API Platform Docker Container Logs Source: https://api-platform.com/docs/symfony/index Displays the logs from the Docker containers of the API Platform project in real-time. The `-f` option allows following the logs as they are generated. ```bash docker compose logs -f ``` -------------------------------- ### Review Resource API Source: https://api-platform.com/docs/symfony/index This section details the operations available for the Review resource, including creation and retrieval. ```APIDOC ## POST /api/reviews ### Description Creates a new review for a book. ### Method POST ### Endpoint /api/reviews ### Request Body - **book** (string) - Required - The IRI of the book to which the review belongs (e.g., "/api/books/1"). - **rating** (integer) - Required - The rating given to the book (1-5). - **body** (string) - Required - The content of the review. - **author** (string) - Required - The author of the review. - **publicationDate** (string) - Optional - The publication date of the review (e.g., "September 21, 2016"). ### Request Example ```json { "book": "/api/books/1", "rating": 5, "body": "Interesting book!", "author": "Kévin", "publicationDate": "September 21, 2016" } ``` ### Response #### Success Response (201 Created) - **@id** (string) - The IRI of the created review resource. - **@type** (string) - The type of the resource (e.g., "Review"). - **@context** (string) - The JSON-LD context. - **book** (string) - The IRI of the book. - **rating** (integer) - The rating given. - **body** (string) - The content of the review. - **author** (string) - The author of the review. - **publicationDate** (string) - The publication date of the review. #### Response Example ```json { "@id": "/api/reviews/1", "@type": "Review", "@context": "/api/contexts/Review", "book": "/api/books/1", "rating": 5, "body": "Interesting book!", "author": "Kévin", "publicationDate": "2016-09-21T00:00:00+00:00" } ``` ## GET /api/reviews ### Description Retrieves a collection of review resources. ### Method GET ### Endpoint /api/reviews ### Query Parameters - **page** (integer) - Optional - The page number for pagination. - **limit** (integer) - Optional - The number of items per page. ### Response #### Success Response (200 OK) - **@id** (string) - The IRI of the collection. - **@type** (string) - The type of the resource (e.g., "hydra:Collection"). - **hydra:member** (array) - An array of review resources. - **hydra:totalItems** (integer) - The total number of items in the collection. #### Response Example ```json { "@id": "/api/reviews", "@type": "hydra:Collection", "hydra:member": [ { "@id": "/api/reviews/1", "@type": "Review", "@context": "/api/contexts/Review", "book": "/api/books/1", "rating": 5, "body": "Interesting book!", "author": "Kévin", "publicationDate": "2016-09-21T00:00:00+00:00" } ], "hydra:totalItems": 1 } ``` ## GET /api/reviews/{id} ### Description Retrieves a specific review resource by its ID. ### Method GET ### Endpoint /api/reviews/{id} #### Path Parameters - **id** (integer) - Required - The ID of the review to retrieve. ### Response #### Success Response (200 OK) - **@id** (string) - The IRI of the review resource. - **@type** (string) - The type of the resource (e.g., "Review"). - **@context** (string) - The JSON-LD context. - **book** (string) - The IRI of the book. - **rating** (integer) - The rating given. - **body** (string) - The content of the review. - **author** (string) - The author of the review. - **publicationDate** (string) - The publication date of the review. #### Response Example ```json { "@id": "/api/reviews/1", "@type": "Review", "@context": "/api/contexts/Review", "book": "/api/books/1", "rating": 5, "body": "Interesting book!", "author": "Kévin", "publicationDate": "2016-09-21T00:00:00+00:00" } ``` ## PATCH /api/reviews/{id} ### Description Updates a specific review resource partially. ### Method PATCH ### Endpoint /api/reviews/{id} #### Path Parameters - **id** (integer) - Required - The ID of the review to update. ### Request Body - **rating** (integer) - Optional - The new rating. - **body** (string) - Optional - The new review content. ### Request Example ```json { "rating": 4, "body": "A good read, but could be better." } ``` ### Response #### Success Response (200 OK) - **@id** (string) - The IRI of the updated review resource. - **@type** (string) - The type of the resource (e.g., "Review"). - **@context** (string) - The JSON-LD context. - **book** (string) - The IRI of the book. - **rating** (integer) - The updated rating. - **body** (string) - The updated content of the review. - **author** (string) - The author of the review. - **publicationDate** (string) - The publication date of the review. #### Response Example ```json { "@id": "/api/reviews/1", "@type": "Review", "@context": "/api/contexts/Review", "book": "/api/books/1", "rating": 4, "body": "A good read, but could be better.", "author": "Kévin", "publicationDate": "2016-09-21T00:00:00+00:00" } ``` ## DELETE /api/reviews/{id} ### Description Deletes a specific review resource by its ID. ### Method DELETE ### Endpoint /api/reviews/{id} #### Path Parameters - **id** (integer) - Required - The ID of the review to delete. ### Response #### Success Response (204 No Content) ``` -------------------------------- ### Create Book Mutation (GraphQL) Source: https://api-platform.com/docs/symfony/index This GraphQL mutation demonstrates how to create a new book entry. It includes fields for ISBN, title, description, author, and publication date, showcasing the mutation capabilities of API Platform with GraphQL. ```graphql mutation { createBook(input: { isbn: "9781782164104", title: "Persistence in PHP with the Doctrine ORM", description: "This book is designed for PHP developers and architects who want to modernize their skills through better understanding of Persistence and ORM.", author: "Kévin Dunglas", publicationDate: "2013-12-01" }) { book { id title } } } ``` -------------------------------- ### Install VichUploaderBundle Source: https://api-platform.com/docs/symfony/file-upload Installs the VichUploaderBundle using Composer. This bundle is a prerequisite for managing file uploads within your Symfony application. ```bash composer require vich/uploader-bundle ``` -------------------------------- ### Book Resource Configuration Examples Source: https://api-platform.com/docs/symfony/controllers Demonstrates different ways to configure API Platform resources and operations, including custom operations and route name conventions. ```APIDOC ## Book Resource Configuration Examples ### Description This section provides examples of how to configure the `App\Entity\Book` resource using various methods, including YAML, XML, and PHP attributes. It highlights the definition of standard and custom operations. ### Configuration Methods #### YAML Configuration ```yaml # api/config/api_platform/resources.yaml resources: App\Entity\Book: operations: ApiPlatform\Metadata\Get: ~ post_publication: class: ApiPlatform\Metadata\Post uriTemplate: /books/{id}/publication controller: App\Controller\CreateBookPublication read: false ``` #### XML Configuration ```xml ``` #### PHP Attributes Configuration ```php // api/src/Entity/Book.php namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\Post; #[ApiResource(operations: [ new Get(), new Post( name: 'publication', uriTemplate: '/books/{id}/publication', controller: CreateBookPublication::class, read: false ) ])] class Book { // ... } ``` ### Alternative Method (using Route Names) #### PHP Attributes with Route Name ```php // api/src/Entity/Book.php namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\Post; #[ApiResource(operations: [ new Get(), new Post(name: 'publication', routeName: 'book_post_publication'), new Post(name: 'book_post_discontinuation') ])] class Book { // ... } ``` ### Note on Custom Controllers When bypassing entity retrieval (`read: false`), the parameter in your custom controller's `__invoke()` method must match the entity identifier in the URI. For example, a path like `/user/{uuid}/bookmarks` requires `__invoke(string $uuid)`. ``` -------------------------------- ### Basic API Platform Test Case with ApiTestCase Source: https://api-platform.com/docs/symfony/testing Demonstrates a basic PHPUnit test class that extends `ApiTestCase`. It shows how to create a client and make a GET request to a '/books' endpoint, with placeholders for assertions. ```php request('GET', '/books'); // your assertions here... } } ``` -------------------------------- ### Start API Platform with Custom Port and Disabled HTTPS Source: https://api-platform.com/docs/symfony/index Starts the API Platform Docker services on a custom HTTP port (8080) and disables HTTPS. It also specifies the server name and trusted hosts. ```bash SERVER_NAME=localhost:80 HTTP_PORT=8080 TRUSTED_HOSTS=localhost docker compose up --wait ``` -------------------------------- ### GraphQL API - Create Book Mutation Source: https://api-platform.com/docs/symfony/index Allows creating a new book using GraphQL mutations. This mutation supports providing all necessary fields for a book. ```APIDOC ## GraphQL API - Create Book Mutation ### Description Creates a new book entry via a GraphQL mutation. ### Method POST ### Endpoint `/graphql` or `/api/graphql` ### Parameters #### Request Body (GraphQL Mutation) ```graphql mutation { createBook(input: { isbn: "9781782164104", title: "Persistence in PHP with the Doctrine ORM", description: "This book is designed for PHP developers and architects who want to modernize their skills through better understanding of Persistence and ORM.", author: "Kévin Dunglas", publicationDate: "2013-12-01" }) { book { id title } } } ``` ### Response #### Success Response Returns the created book's ID and title. #### Response Example ```json { "data": { "createBook": { "book": { "id": "1", "title": "Persistence in PHP with the Doctrine ORM" } } } } ``` ``` -------------------------------- ### Install Symfony Messenger Source: https://api-platform.com/docs/symfony/messenger Installs the Symfony Messenger component using Composer. This is a prerequisite for enabling asynchronous message processing with API Platform. ```bash composer require symfony/messenger ``` -------------------------------- ### GraphQL API - List Books Query with Relations Source: https://api-platform.com/docs/symfony/index Allows fetching a list of books with pagination, total count, and nested details of related reviews. ```APIDOC ## GraphQL API - List Books Query with Relations ### Description Retrieves a paginated list of books, including their total count and nested review information. ### Method POST ### Endpoint `/graphql` or `/api/graphql` ### Parameters #### Request Body (GraphQL Query) ```graphql { books { totalCount edges { node { id title reviews { totalCount edges { node { author rating } } } } } } } ``` ### Response #### Success Response Returns a list of books with pagination details and nested review data. #### Response Example ```json { "data": { "books": { "totalCount": 10, "edges": [ { "node": { "id": "/books/1", "title": "Book One", "reviews": { "totalCount": 5, "edges": [ { "node": { "author": "Reviewer A", "rating": 4 } }, { "node": { "author": "Reviewer B", "rating": 5 } } ] } } } ] } } } ``` ``` -------------------------------- ### Synchronize Project with API Platform Template Source: https://api-platform.com/docs/symfony/index Shell command to synchronize your project with the latest API Platform template using a provided script. This helps in updating your project with recent enhancements, especially for features like FrankenPHP. ```bash curl -sSL https://raw.githubusercontent.com/coopTilleuls/template-sync/main/template-sync.sh | sh -s -- https://github.com/api-platform/api-platform ``` -------------------------------- ### Install DoctrineTestBundle for Database Reset Source: https://api-platform.com/docs/symfony/testing Installs the DAMA/DoctrineTestBundle, which automatically resets the database before each test, ensuring a clean state for functional testing. This is a development dependency. ```bash composer require --dev dama/doctrine-test-bundle ``` -------------------------------- ### Book Resource Source: https://api-platform.com/docs/symfony/index Defines the 'Book' resource with its properties and relationships, enabling API Platform to generate CRUD operations and documentation for books. ```APIDOC ## GET /books ### Description Retrieves a collection of book resources. ### Method GET ### Endpoint /books ### Parameters #### Query Parameters - **page** (integer) - Optional - The page number for pagination. - **itemsPerPage** (integer) - Optional - The number of items to display per page. ### Request Example ```json { "example": "GET /books?page=1&itemsPerPage=10" } ``` ### Response #### Success Response (200) - **hydra:member** (array) - A list of book objects. - **hydra:totalItems** (integer) - The total number of books available. #### Response Example ```json { "@context": "/contexts/Book", "@id": "/books", "@type": "hydra:Collection", "hydra:member": [ { "@id": "/books/1", "@type": "/books", "id": 1, "isbn": "978-0321765723", "title": "The Lord of the Rings", "description": "An epic high-fantasy novel.", "author": "J.R.R. Tolkien", "publicationDate": "1954-07-29T00:00:00+00:00", "reviews": [] } ], "hydra:totalItems": 1 } ``` ``` ```APIDOC ## POST /books ### Description Creates a new book resource. ### Method POST ### Endpoint /books ### Parameters #### Request Body - **isbn** (string) - Optional - The ISBN of the book. - **title** (string) - Required - The title of the book. - **description** (string) - Optional - The description of the book. - **author** (string) - Required - The author of the book. - **publicationDate** (string) - Optional - The publication date of the book (ISO 8601 format). ### Request Example ```json { "isbn": "978-0743273565", "title": "The Great Gatsby", "description": "A novel about the American dream.", "author": "F. Scott Fitzgerald", "publicationDate": "1925-04-10T00:00:00Z" } ``` ### Response #### Success Response (201 Created) - **id** (integer) - The unique identifier of the created book. - **isbn** (string) - The ISBN of the book. - **title** (string) - The title of the book. - **description** (string) - The description of the book. - **author** (string) - The author of the book. - **publicationDate** (string) - The publication date of the book. - **reviews** (array) - An empty array, as reviews are added separately. #### Response Example ```json { "@context": "/contexts/Book", "@id": "/books/2", "@type": "/books", "id": 2, "isbn": "978-0743273565", "title": "The Great Gatsby", "description": "A novel about the American dream.", "author": "F. Scott Fitzgerald", "publicationDate": "1925-04-10T00:00:00+00:00", "reviews": [] } ``` ``` ```APIDOC ## GET /books/{id} ### Description Retrieves a specific book resource by its ID. ### Method GET ### Endpoint /books/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the book. ### Request Example ```json { "example": "GET /books/1" } ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the book. - **isbn** (string) - The ISBN of the book. - **title** (string) - The title of the book. - **description** (string) - The description of the book. - **author** (string) - The author of the book. - **publicationDate** (string) - The publication date of the book. - **reviews** (array) - A list of reviews associated with the book. #### Response Example ```json { "@context": "/contexts/Book", "@id": "/books/1", "@type": "/books", "id": 1, "isbn": "978-0321765723", "title": "The Lord of the Rings", "description": "An epic high-fantasy novel.", "author": "J.R.R. Tolkien", "publicationDate": "1954-07-29T00:00:00+00:00", "reviews": [ { "@id": "/reviews/1", "@type": "/reviews", "id": 1, "rating": 5, "body": "A masterpiece!", "author": "Jane Doe", "publicationDate": "2023-01-15T10:00:00+00:00", "book": "/books/1" } ] } ``` ``` ```APIDOC ## PUT /books/{id} ### Description Updates an existing book resource. ### Method PUT ### Endpoint /books/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the book to update. #### Request Body - **isbn** (string) - Optional - The ISBN of the book. - **title** (string) - Required - The title of the book. - **description** (string) - Optional - The description of the book. - **author** (string) - Required - The author of the book. - **publicationDate** (string) - Optional - The publication date of the book (ISO 8601 format). ### Request Example ```json { "isbn": "978-0321765723", "title": "The Lord of the Rings (Updated)", "description": "An epic high-fantasy novel, revised edition.", "author": "J.R.R. Tolkien", "publicationDate": "1954-07-29T00:00:00Z" } ``` ### Response #### Success Response (200 OK) - **id** (integer) - The unique identifier of the updated book. - **isbn** (string) - The ISBN of the book. - **title** (string) - The title of the book. - **description** (string) - The description of the book. - **author** (string) - The author of the book. - **publicationDate** (string) - The publication date of the book. - **reviews** (array) - A list of reviews associated with the book. #### Response Example ```json { "@context": "/contexts/Book", "@id": "/books/1", "@type": "/books", "id": 1, "isbn": "978-0321765723", "title": "The Lord of the Rings (Updated)", "description": "An epic high-fantasy novel, revised edition.", "author": "J.R.R. Tolkien", "publicationDate": "1954-07-29T00:00:00+00:00", "reviews": [] } ``` ``` ```APIDOC ## DELETE /books/{id} ### Description Deletes a specific book resource by its ID. ### Method DELETE ### Endpoint /books/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the book to delete. ### Request Example ```json { "example": "DELETE /books/1" } ``` ### Response #### Success Response (204 No Content) No response body is returned upon successful deletion. #### Response Example ```json { "example": "(No Content)" } ``` ```