Rest Controller Conventions logo

Rest Controller Conventions

Community
fatonh
rest-controller-conventions

Use when writing hand-rolled REST controllers in Symfony (without API Platform) — routing attributes, HTTP status codes, request payload mapping, serialization groups, pagination, and versioning. Use when generating controllers, JSON endpoints, or resource routes.

Overview

Publisherfatonh
Repositorysymfony-skills
Skill namerest-controller-conventions
Stars
36
Forks
3
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by fatonh on GitHub. Read the source before you install it.

Installation

Install the Rest Controller Conventions AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/fatonh/symfony-skills/tree/main/skills/rest-controller-conventions
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/fatonh/symfony-skills.git /tmp/symfony-skills
mkdir -p .claude/skills
cp -r /tmp/symfony-skills/skills/rest-controller-conventions .claude/skills/rest-controller-conventions
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Rest Controller Conventions in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Rest Controller Conventions on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Rest Controller Conventions is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

REST Controller Conventions (Symfony, no API Platform)

Controller shape

  • One final class per resource, #[Route] prefix on the class.
  • Constructor injection of services only (no repositories — see layered-architecture).
  • Map the request body with #[MapRequestPayload] and query params with #[MapQueryString] into DTOs.
  • Return JsonResponse via $this->json(...) with explicit status codes.
php
#[Route('/api/orders')]
final class OrderController extends AbstractController
{
    public function __construct(private readonly OrderService $orders) {}

    #[Route('', methods: ['GET'])]
    public function list(#[MapQueryString] OrderListQuery $query): JsonResponse
    {
        $page = $this->orders->list($query);

        return $this->json($page, context: ['groups' => ['order:read']]);
    }

    #[Route('/{id}', methods: ['GET'])]
    public function show(Uuid $id): JsonResponse
    {
        return $this->json(
            $this->orders->get($id),
            context: ['groups' => ['order:read', 'order:detail']],
        );
    }

    #[Route('', methods: ['POST'])]
    public function create(#[MapRequestPayload] CreateOrderRequest $request): JsonResponse
    {
        $order = $this->orders->createOrder($request);

        return $this->json(
            OrderResponse::fromEntity($order),
            Response::HTTP_CREATED,
            ['Location' => $this->generateUrl('order_show', ['id' => $order->getId()])],
            ['groups' => ['order:read']],
        );
    }

    #[Route('/{id}', methods: ['DELETE'])]
    public function delete(Uuid $id): JsonResponse
    {
        $this->orders->cancel($id);

        return new JsonResponse(null, Response::HTTP_NO_CONTENT);
    }
}

HTTP status codes

SituationStatus
Successful GET200 OK
Resource created201 Created + Location header
Accepted, processed async202 Accepted
Successful DELETE / no body204 No Content
Validation failed422 Unprocessable Entity
Malformed JSON400 Bad Request
Unauthenticated401 Unauthorized
Authenticated but forbidden403 Forbidden
Not found404 Not Found
Conflict (duplicate, version)409 Conflict

Don't return 200 for everything. Map domain exceptions to status codes in an exception listener (see problem-details-rfc9457).

Serialization groups, not entity exposure

Never serialize a Doctrine entity straight to the client without scoping. Either map to a response DTO or apply #[Groups] and pass the group in the serialization context.

php
// On the entity / DTO
#[Groups(['order:read'])]
private string $customerEmail;

#[Groups(['order:detail'])]   // only on the detail endpoint
private array $internalNotes;

Request mapping & validation

#[MapRequestPayload] deserializes and validates the DTO (via the Validator). On constraint failure it throws automatically → your exception listener turns it into a 422.

php
public function create(#[MapRequestPayload] CreateOrderRequest $request): JsonResponse

Validate query params the same way with #[MapQueryString]. See dto-and-validation.

Pagination

Return a stable envelope, never a bare array, so you can add metadata without a breaking change:

json
{
  "data": [ ... ],
  "page": 1,
  "perPage": 20,
  "total": 137
}
php
return $this->json(new PaginatedResponse($items, $page, $perPage, $total), context: ['groups' => ['order:read']]);

Cap perPage server-side. For deep pages, prefer keyset pagination (see doctrine-query-optimization).

Routing conventions

  • Plural nouns: /orders, /orders/{id}, /orders/{id}/lines.
  • No verbs in paths (/orders POST, not /createOrder).
  • Use HTTP methods for actions; reserve sub-resources for relationships.
  • Constrain params: #[Route('/{id}', requirements: ['id' => Requirement::UUID])].

Gotchas

  • Agent returns $this->json($entity) without groups — scope with #[Groups] or map to a DTO; otherwise lazy associations serialize and leak fields.
  • Agent returns 200 for created/deleted resources — use 201 (+ Location) and 204.
  • Agent decodes JSON by hand (json_decode($request->getContent())) — use #[MapRequestPayload] + DTO.
  • Agent puts verbs in routes (/getOrders, /createOrder) — use nouns + HTTP methods.
  • Agent returns a bare JSON array for collections — use a paginated envelope.
  • Agent catches NotFoundException in the controller — let the exception listener map it to 404.
  • Agent skips param requirements — constrain {id} to UUID to avoid route collisions.

Frequently asked questions

What does the Rest Controller Conventions AI skill do?

Use when writing hand-rolled REST controllers in Symfony (without API Platform) — routing attributes, HTTP status codes, request payload mapping, serialization groups, pagination, and versioning. Use when generating controllers, JSON endpoints, or resource routes.

Why use Rest Controller Conventions on TypingMind?

Because you install it once and use it with any model. Rest Controller Conventions is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Rest Controller Conventions in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/fatonh/symfony-skills/tree/main/skills/rest-controller-conventions. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Rest Controller Conventions?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Rest Controller Conventions?

As many as you like. As long as a model supports skills, you can use Rest Controller Conventions with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Rest Controller Conventions AI skill free?

Yes. It is published on GitHub by fatonh under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇