moxie/querystrings-and-config

Querystrings & config.js

The Router loads config.js for the matched route and merges defaults with the incoming querystring according to querystrings.options.

querystrings.default

  • Key/value pairs applied before or alongside parsing (depending on handler) so optional params have sane defaults.
  • Example: size: 10, from: 0.

querystrings.options

Each key can define:

  • type — one of:
    • string
    • number
    • csv (comma-separated list)
    • boolean
    • rewrite (transform incoming value)
  • Additional constraints (allowed values, required flags) as supported by the Router / querystring module — mirror a live endpoint for exact keys.

Why centralize here?

  • Single source of truth for validation — avoids diverging checks in index.js and helpers/querystrings.js.
  • Automatic error responses for invalid types where the stack supports it.

JSON:API helpers

For jsonapi endpoints, helpers/querystrings.js maps public query params to backend params (Spark, Brightcove, internal search, etc.). Keep public names stable for mobile/web clients; translate internally when upstream APIs differ.

Variable-specific configs

If the route has {version} (or similar), you can add:

.../my.endpoint/{version}/config.js

The Router merges variable-specific config.js over the base file — use for version-gated defaults without forking the whole handler.

Debugging

  • ?debugga=config — merged config after query processing
  • ?debugga=request.querystrings — parsed result