Skip to content

feat: support dynamic HTTP response status code via request attribute#7904

Open
Griffon-Weglot wants to merge 1 commit intoapi-platform:mainfrom
Griffon-Weglot:main
Open

feat: support dynamic HTTP response status code via request attribute#7904
Griffon-Weglot wants to merge 1 commit intoapi-platform:mainfrom
Griffon-Weglot:main

Conversation

@Griffon-Weglot
Copy link
Copy Markdown

Q A
Branch? main
Tickets Closes #7903
License MIT
Doc PR api-platform/docs#...

Allow processors to dynamically override the HTTP response status code by setting the _api_response_status request attribute.

Use case: A single POST endpoint that returns 200 when the operation is processed synchronously, and 202 when it is dispatched asynchronously.

  // In a processor                                                                                                                                                                                                                         
  $request = $context['request'] ?? null;                                                                                                                                                                                                     
  $request?->attributes->set('_api_response_status', 200);                                                                                                                                                                                  

The change is fully backward-compatible: when the attribute is not set, the existing behavior is unchanged.

@VincentLanglet VincentLanglet requested a review from soyuka April 2, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide an easy way to override the status code dynamically

1 participant