api-platform / api-platform/core

[Feature] Content negociation for Custom Action/Controller

Offen
#1,423 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
PHP
Sterne
2.6k
Forks
980
Ø Merge
2 T. 5 Std.
Gemergte PRs (30 T.)
48

Beschreibung

Hi,

It would be great to be able to create Custom Action / Controller not directly linked to any entity but enable the same kind of content negotiation as for the other routes.

For example, if I wants to enable the Content Negotiation request /response listener, I have to add ``defaults={"_api_resource_class"=Foo::class, "_api_collection_operation_name"=""})``:

```php
final class MySpecificAction
{
private $myService;

public function __construct(MyService $myService)
{
$this->myService = $myService;
}

/**
* @Route(name="api_process_things", path="/task/process/things",
* defaults={"_api_resource_class"=Foo::class, "_api_collection_operation_name"=""})
* @Method({"POST"})
*/
public function __invoke()
{
return $this->myService->pocessThings();
}
}
```
Without I need to return a JsonResponse manually if the Accept is application/json (which is not really a problem) but I case the Firewall return an Access Denied (because my role is not allowed to access the route), the response is returned in HTML.

With ``_api_resource_class`` and ``_api_collection_operation_name`` defined, it works but it's hacked because I need to provide an Entity which doesn't correspond to the process and an empty operation_name. It would be better if we could just provide an option to enable the content negotiation. For example ``defaults={"_api_resource_negotiation"=true}``

What do you think about that?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.