Skip to main content

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

ShapeWhenTemplate
Serializer-onlyComponent appears in search/show JSON; no new HTTP routesdecidim-restfull-surveys
Read-only HTTPGET index/show onlyDecidim::RestFull::Routing.read_resources — see Routing
Async CRUDMutations return 202 + job pollDecidim::RestFull::Routing.async_resources + ext.api_job — see Async
Host-app one-offTenant-specific API in the host Decidim appHost app extensions + Boot and extension

External gem checklist

  1. Gemspec — depend on decidim-restfull-core and the matching decidim-<feature> gem.
  2. ENGINE_ROOT — set in lib/decidim-restfull-<feature>.rb (see RestFull engines).
  3. Rails enginelib/decidim/rest_full/<feature>/engine.rb with initializer before: "rest_full.draw_routes" (and before: "rest_full.scopes" as a safety belt).
  4. Extension.register in that initializer:
    • ext.oauth_scopes — only scopes not already in core (:meetings, :debates, … are built-in)
    • ext.permissions
    • ext.routes — use Routing DSL
    • ext.api_job for async mutations
    • ext.rswag_specs + ext.open_api_definitions
  5. Controller under app/controllers/decidim/api/rest_full/ — see Controllers.
  6. Request spec — see RSwag.
  7. 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.rb GEMS
  • Gate the feature via the Restfull organization Toggle tab (ModuleAvailability) — do not add process-wide Configuration.enable_*_api
  • Add available_permissions in configuration.rb when the feature owns a permission group
  • Run ./bin/check in Docker

When something breaks

SymptomLikely causeFix
404 on new pathRoutes registered after first drawBoot and extension — initializer order or append API
Scope missing on tokenScopes registered too latebefore: "rest_full.scopes"; see Scopes and permissions
OpenAPI path missingRSwag glob not registeredext.rswag_specs + regenerate — Generate clients

See also