Rails API
Reads config/routes.rb and db/schema.rb to generate tools for a Rails API-only app. Controllers are not executed; everything works from static files.
Prerequisites
Section titled “Prerequisites”- A Rails 7 project folder (
config/application.rb,config/routes.rb,db/schema.rbpresent). - To run the demo server: Ruby 3.1 or newer and Bundler 2.
appctlinstalled.
The demo in this repo
Section titled “The demo in this repo”examples/demos/rails-api/ is an API-only Rails 7.1 app with Post and Comment resources mounted under /api/v1/. The static files that appctl reads are committed. You can run the sync without installing Ruby.
Sync without running Ruby
Section titled “Sync without running Ruby”cd examples/demos/rails-apiappctl sync --rails . --base-url http://127.0.0.1:3001 --forceReal output:
Synced Rails: 2 resources, 10 tools written to .appctlGenerated tools:
post: posts_list GET /api/v1/posts, post_get GET /api/v1/posts/{id}, post_create POST /api/v1/posts, post_update PATCH /api/v1/posts/{id}, post_delete DELETE /api/v1/posts/{id}comment: same five tools under /api/v1/commentsIf you see singular paths (/api/v1/post) you are on an older appctl. Upgrade past 0.2.0.
Run the live server (optional)
Section titled “Run the live server (optional)”Ruby 3.1 or newer is required. Use rbenv, asdf, or rvm if your system Ruby is older.
ruby -v # should print 3.1 or higherbundle installbundle exec rake db:create db:migratebundle exec rails server -p 3001Verify:
curl -s -X POST http://127.0.0.1:3001/api/v1/posts \ -H "Content-Type: application/json" \ -d '{"post":{"title":"hi","body":"hello"}}'What appctl reads
Section titled “What appctl reads”config/routes.rb: onlyresources :foolines insidenamespaceblocks are parsed.db/schema.rb:create_table "foos"blocks, for field names and types.
Controllers are not read. Strong parameters are not inspected. Custom routes (get "/foo/bar") are ignored.
Known limits
Section titled “Known limits”- Namespaced routes deeper than one level are not parsed.
- Custom serializers and jbuilder views do not affect the generated tools.
- No
has_many/belongs_torelation awareness yet.