Skip to content
Back to skills

Symfony Api Response

ASecurity

Symfony API response standardization — JSON payload format, exception handling, controllers, REST endpoints, error responses, debug mode. Triggers on: API, endpoint, controller, response, error handling, JSON, REST, API response, exception subscriber, HTTP

  • 34 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 26, 2026
developmentgophpapisecurity

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned May 27, 2026

npx -y skills add aligundogdu/symfony-hexagonal-skill --skill symfony-api-response --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Symfony Api Response?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Symfony Api Response
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/aligundogdu-symfony-api-response/badge)](https://www.skillsdirectory.com/skills/aligundogdu-symfony-api-response)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
description: "Symfony API response standardization — JSON payload format, exception handling, controllers, REST endpoints, error responses, debug mode. Triggers on: API, endpoint, controller, response, error handling, JSON, REST, API response, exception subscriber, HTTP"
---

# Symfony API Response Standard

You are an expert in building standardized REST APIs within Symfony hexagonal architecture.

## When to Activate

- User creates API endpoints or controllers
- User asks about response format or error handling
- User needs exception handling for APIs
- User mentions REST, JSON, or API design

## Standard JSON Payload

ALL API responses use this format:

```json
{
    "result": null,
    "error": null,
    "extra": null,
    "status": 200
}
```

| Field | Type | Description |
|-------|------|-------------|
| `result` | `mixed` | Success data (null on error) |
| `error` | `?object` | Error details (null on success) |
| `extra` | `?object` | Metadata: pagination, debug info |
| `status` | `int` | HTTP status code |

### Success Response
```json
{
    "result": {"id": "uuid-123", "name": "John"},
    "error": null,
    "extra": null,
    "status": 200
}
```

### Error Response
```json
{
    "result": null,
    "error": {"code": "USER_NOT_FOUND", "message": "User not found"},
    "extra": null,
    "status": 404
}
```

### Debug Mode (APP_DEBUG=true)
```json
{
    "result": null,
    "error": {"code": "INTERNAL_ERROR", "message": "Something went wrong"},
    "extra": {"debug": {"exception": "...", "trace": "..."}},
    "status": 500
}
```

## Controller Pattern

Controllers are thin — dispatch to buses only:

```php
namespace App\Presentation\{Module}\API;

use App\Presentation\Shared\ApiResponseTrait;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

#[Route('/api/{module}')]
final class {Entity}Controller
{
    use ApiResponseTrait;

    public function __construct(
        private readonly MessageBusInterface $commandBus,
        private readonly MessageBusInterface $queryBus,
    ) {
    }

    #[Route('', methods: ['POST'])]
    #[IsGranted('ROLE_...')] // ALWAYS include
    public function create(Request $request): JsonResponse
    {
        // 1. Parse input
        // 2. Create command
        // 3. Dispatch to command bus
        // 4. Return success response
    }
}
```

## References

See `references/` for detailed guides:
- `payload-schema.md` — ApiResponseTrait, response helpers
- `exception-handling.md` — ExceptionSubscriber, error mapping

Files in this skill

  • SKILL.md2.5 KB
  • references/exception-handling.md5.2 KB
  • references/payload-schema.md4.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.