diff --git a/core/content-negotiation.md b/core/content-negotiation.md index cea71698269..c1b227a7a1a 100644 --- a/core/content-negotiation.md +++ b/core/content-negotiation.md @@ -94,10 +94,10 @@ api_platform: ## Configuring Formats For a Specific Resource or Operation -Support for specific formats can also be configured at resource and operation level using the `input_formats` and `output_formats` attributes. -`input_formats` controls the formats accepted in request bodies while `output_formats` controls formats available for responses. +Support for specific formats can also be configured at resource and operation level using the `inputFormats` and `outputFormats` attributes. +`inputFormats` controls the formats accepted in request bodies while `outputFormats` controls formats available for responses. -The `formats` attribute can be used as a shortcut, it sets both the `input_formats` and `output_formats` in one time. +The `format` attribute can be used as a shortcut, it sets both the `inputFormats` and `outputFormats` in one time. ```php Book::class, - '_api_item_operation_name' => 'post_publication', + '_api_operation_name' => '_api_/books/{id}/publication_post', ], )] public function __invoke(Book $book): Book @@ -392,8 +392,7 @@ class CreateBookPublication extends AbstractController } ``` -It is mandatory to set `_api_resource_class` and `_api_item_operation_name` (or `_api_collection_operation_name` for a collection -operation) in the parameters of the route (`defaults` key). It allows API Platform to work with the Symfony routing system. +It is mandatory to set `_api_resource_class` and `_api_operation_name` in the parameters of the route (`defaults` key). It allows API Platform to work with the Symfony routing system. Alternatively, you can also use a traditional Symfony controller and YAML or XML route declarations. The following example does the same thing as the previous example: diff --git a/core/errors.md b/core/errors.md index a02033e9561..043d583e124 100644 --- a/core/errors.md +++ b/core/errors.md @@ -110,7 +110,7 @@ In any other cases, your exception message will be sent to end users. ## Fine-grained Configuration -The `exception_to_status` configuration can be set on resources and operations: +The `exceptionToStatus` configuration can be set on resources and operations: ```php Book::class, + '_api_operation_name' => '_api_/books/{id}/publication_post', + ], + methods: ['POST'], + )] + public function __invoke(Book $book): Book + { + $this->bookPublishingHandler->handle($book); + + return $book; + } +} +``` + +It is mandatory to set `_api_resource_class` and `_api_operation_name`in the parameters of the route (`defaults` key). It allows API Platform to work with the Symfony routing system. + +Alternatively, you can also use a traditional Symfony controller and YAML or XML route declarations. The following example does +the exact same thing as the previous example: + +```php +handle($book); + } +} +``` + +```yaml +# api/config/routes.yaml +book_post_publication: + path: /books/{id}/publication + methods: ['POST'] + defaults: + _controller: App\Controller\BookController::createPublication + _api_resource_class: App\Entity\Book + _api_operation_name: post_publication +``` ## Expose a Model Without Any Routes @@ -502,7 +571,6 @@ Then, remove the route from the decorator: ```php