A set of Ruby gems for building opinionated JSON APIs on Rails.
This repository is a monorepo containing four gems whose versions stay in lockstep:
| Gem | What it is | Depends on |
|---|---|---|
| api_serializer | Declarative DSL for serializing Ruby objects to JSON with typed, versioned schemas. | literal |
| api_query_language | Filter / sort query-language parser. Produces a backend-agnostic AST. | literal, racc |
| api_query_language-active_record | ActiveRecord backend for the above — adds apply_to(relation), plus QueryContext / NodeWithContext for custom visitors. |
api_query_language, activerecord |
| another_api | Rails engine wiring the three above together with ActionPolicy and Dry::Monads into a JSON API base controller. | api_serializer, api_query_language, api_query_language-active_record, rails, action_policy, dry-monads |
api_serializer and api_query_language are useable outside Rails.
Pick the level you need:
# Just the serializer — any Ruby app
gem "api_serializer"
# Just the query-language parser — any Ruby app
gem "api_query_language"
# Query language + ActiveRecord application
gem "api_query_language-active_record"
# Full Rails engine (brings in all of the above)
gem "another_api"Per-gem quickstart is in each gem's README.
bundle install # installs all four gemspecs as path gems
bundle exec rake # runs tests across all four gems, then standardrb once at the repo rootIndividual gem test suites:
cd api_serializer && bundle exec rake test
cd api_query_language && bundle exec rake test
cd api_query_language_active_record && bundle exec rake test
cd another_api && bundle exec rake testThe api_query_language-active_record suite uses in-memory SQLite by default.
To run the full suite including PG-only tests (array/jsonb columns), set
DATABASE_URL:
DATABASE_URL=postgres://user:pass@host/test_db bundle exec rake testSee CONTRIBUTING.md for more.
MIT. See LICENSE.txt.
These gems were extracted from the Confinus project. Thanks to them for the original implementation.