stanlemon/rest-bundle
Stanlemon RestBundle is a Symfony bundle for building RESTful APIs with less boilerplate, offering annotation-driven routing, serialization support, and reusable controller utilities so PHP developers can expose resources quickly and consistently.
Check compatibility first. This bundle is archived and targets the Symfony 2.x/3.x era (PHP 5.6–7.x). On a modern app you will almost certainly need a maintained fork or a pinned set of dependencies. Treat composer require stanlemon/rest-bundle as a spike, not a production install, until composer why-not is clean.
Register the bundle in app/AppKernel.php (or config/bundles.php on Symfony 3.4+/4):
new StanLeMon\RestBundle\StanLeMonRestBundle(),
Confirm the routing mechanism before writing config. This bundle generates routes from entity configuration rather than from controller annotations. Depending on the version, routes are either registered automatically from the bundle config or must be imported through a custom route loader in app/config/routing.yml (the usual pattern is a type: stanlemon_rest import). Check Resources/config/ and the README for the exact import line for your version.
Look here first, in this order: README.md → DependencyInjection/Configuration.php (the authoritative list of config keys and defaults) → the base resource controller under Controller/ → the route loader. The Configuration.php file is the fastest way to discover what is actually supported in the version you installed.
Minimal configuration is a mapping from a Doctrine entity to a URL path:
# app/config/config.yml
stanlemon_rest:
resources:
AppBundle\Entity\Post:
path: /api/posts
# controller, form type, serialization groups, methods, etc. vary by version
First use case: expose a single, simple entity (no deep associations) as a CRUD resource, verify with bin/console debug:router | grep api/posts, then exercise it:
curl -i http://localhost/app_dev.php/api/posts
curl -i -X POST http://localhost/app_dev.php/api/posts \
-H 'Content-Type: application/json' \
-d '{"title":"Hello"}'
Get the read path working before enabling writes; most problems surface in serialization and form binding, not in routing.
post_list, post_read, post_write) so collections return shallow representations and item reads return the full object. This is the single most effective way to avoid recursion and accidental data exposure./posts/{id}/comments) or relationship management out of the box. Register those as ordinary Symfony controllers alongside the generated ones.stateless: true firewall for the API prefix and use access_control for coarse-grained rules. Fine-grained ownership checks belong in a voter invoked from a custom controller or a kernel event listener.{data, meta, errors} shape before clients depend on the raw output.nelmio/cors-bundle and, if you need XML or versioned media types, a format listener. Assume JSON-only unless you verify otherwise.@MaxDepth/circular-reference handlers on the serializer, not by marking relations @Ignore permanently.PUT replaces the whole entity or merges; if it merges, you cannot null out fields, and if it replaces, clients will accidentally wipe data. Document the behavior and prefer PATCH semantics where supported.InvalidArgumentException/form exceptions so clients get field-level errors.bin/console cache:clear after every resource edit — stale route caches are a frequent source of "my new endpoint 404s."bin/console debug:router --show-controllers to confirm which controller actually wins.debug:router for generated routes, debug:config stanlemon_rest (Symfony 3.2+) for the resolved configuration, the profiler's Doctrine panel for query counts, and debug:container to find the resource controller service ID if you want to decorate it.composer update and this package will not receive fixes upstream.How can I help you explore Laravel packages today?