Recipe
Overview
For: maintainers of a decidim-restfull-* gem (or an external RestFull extension gem) adding HTTP endpoints.
Not for: calling the API from a client app — use Operating the API and ReDoc instead.
Follow this page in order. Open topic pages only when you need a single concern (async, RSwag, serializers, …).
Choose your shape
| Shape | When | Template |
|---|---|---|
| Serializer-only | Component appears in search/show JSON; no new HTTP routes | decidim-restfull-surveys |
| Read-only HTTP | GET index/show only | Decidim::RestFull::Routing.read_resources — see Routing |
| Async CRUD | Mutations return 202 + job poll | Decidim::RestFull::Routing.async_resources + ext.api_job — see Async |
| Host-app one-off | Tenant-specific API in the host Decidim app | Host app extensions + Boot and extension |
External gem checklist
- Gemspec — depend on
decidim-restfull-coreand the matchingdecidim-<feature>gem. ENGINE_ROOT— set inlib/decidim-restfull-<feature>.rb(see RestFull engines).- Rails engine —
lib/decidim/rest_full/<feature>/engine.rbwith initializerbefore: "rest_full.draw_routes"(andbefore: "rest_full.scopes"as a safety belt). Extension.registerin that initializer:ext.oauth_scopes— only scopes not already in core (:meetings,:debates, … are built-in)ext.permissionsext.routes— use Routing DSLext.api_jobfor async mutationsext.rswag_specs+ext.open_api_definitions
- Controller under
app/controllers/decidim/api/rest_full/— see Controllers. - Request spec — see RSwag.
- Verify (Docker):
docker compose exec rest_full bash -lc 'cd /home/module && bundle exec rails routes -g rest_full | head'
docker compose exec rest_full bash -lc 'cd /home/module && RAILS_ENV=test bundle exec rspec <your-spec-path>'
Monorepo-only extras
When adding a gem inside the decidim-restfull/ monorepo, also:
- Register the gem in
decidim-restfull/decidim-restfull.gemspec - Add the gem to
gem_spec_paths.rbGEMS - Gate the feature via the Restfull organization Toggle tab (
ModuleAvailability) — do not add process-wideConfiguration.enable_*_api - Add
available_permissionsinconfiguration.rbwhen the feature owns a permission group - Run
./bin/checkin Docker
When something breaks
| Symptom | Likely cause | Fix |
|---|---|---|
| 404 on new path | Routes registered after first draw | Boot and extension — initializer order or append API |
| Scope missing on token | Scopes registered too late | before: "rest_full.scopes"; see Scopes and permissions |
| OpenAPI path missing | RSwag glob not registered | ext.rswag_specs + regenerate — Generate clients |
See also
- Boot and extension — boot order,
Extension.register, append API - RestFull engines — gem layout
- CONTRIBUTING.md — covenant and
./bin/check