Routes live with actions
Each action declares its own route. No central routes file to keep in sync.
One class per endpoint. Typed input, compiled templates and a SQL-first ORM — all checked by the compiler.
The route, the input it accepts, the logic and the response sit side by side — open one folder and the whole endpoint is in front of you.
class Posts::CreatePost < Blog::BaseAction
post "/posts"
call do
input = validate(CreatePostContract)
post = store.create_post(author_id: input.author_id, title: input.title)
render status_code: 201
end
endclass Posts::CreatePostContract < RequestValidation::Contract
schema do
required :author_id, Int64
required :title, String, filled: true, max_size: 200
end
endjson.id post.id
json.title post.titleEvery action reads the same way, top to bottom.
post "/posts"validate(CreatePostContract)store.create_post(...)create_post.jbuilderdependencies:
runcobo:
github: runcobo/runcobo
version: ~> 3.1shards install # also builds bin/cobo