Coming from Lucky
Lucky and Runcobo share the core idea: one class per action, with its route declared inside it and as much as possible checked by the compiler. Pipes even have the same names. The main differences are how input is read, how responses are rendered and how the database is accessed.
At a glance
| Lucky | Runcobo |
|---|---|
class Posts::Show < ApiAction | class Posts::ShowPost < Blog::BaseAction |
get "/posts/:post_id" do ... end | get "/posts/:id" + call do ... end |
Route params as methods (post_id) | Contract fields: validate(ShowPostContract).id |
params.from_json, operation params | One contract for path, query and body |
before require_sign_in / after / skip | before / after / skip — the same |
A pipe returns continue | A filter returns anything; byebye halts (continue also works) |
json(...), serializers | render_json(...), or Jbuilder templates |
| HTML pages and components | Water templates, layouts and partials |
| Avram models and query objects | Named SQL queries → a typed store |
SaveOperation validations | Contracts for input; constraints in SQL for data |
| Avram migrations (Crystal DSL) | Plain SQL migrations |
lucky dev | bin/cobo dev |
lucky routes | bin/cobo routes |
lucky db.migrate | bin/cobo db migrate |
An action
# Lucky
class Api::Posts::Show < ApiAction
get "/api/posts/:post_id" do
post = PostQuery.find(post_id)
json PostSerializer.new(post)
end
end# Runcobo
class Posts::ShowPost < Blog::BaseAction
get "/posts/:id"
call do
input = validate(ShowPostContract)
if post = store.get_post?(id: input.id)
render # → show_post.jbuilder
else
render_json({error: "post_not_found"}, status_code: 404)
end
end
endclass Posts::ShowPostContract < RequestValidation::Contract
schema do
required :id, Int64
end
endjson.id post.id
json.title post.titleThe path parameter is declared with a type in the contract, so /posts/abc is a 422 before your code runs, and the same contract also reads query and body fields.
Pipes are filters
abstract class Blog::AdminAction < Blog::BaseAction
before require_admin
private def require_admin
unless admin?
render_json({error: "forbidden"}, status_code: 403)
return byebye
end
end
endThe behavior matches Lucky's pipes: filters run in declaration order, are inherited, and skip require_admin removes an inherited one. A filter that doesn't return byebye lets the request continue.
Avram becomes SQL
Instead of models and query objects, write each query in SQL and generate typed methods:
-- name: ListPublishedPosts :many
SELECT id, title FROM posts WHERE published_at IS NOT NULL ORDER BY published_at DESC;store.list_published_posts # => Array(Blog::Store::ListPublishedPostsRow)Both approaches are type-safe; Runcobo checks the SQL against your migrations when you run bin/cobo generate, and the result types come from the database schema. Related records are loaded explicitly, with a JOIN or one batch query.
Pages become templates
Lucky renders HTML with page classes. Runcobo uses Water templates that sit beside the action, rendered with render engine: :water or by default after Runcobo.views "src/actions", engine: :water. See Views.
What's different
- Input is a contract, not a method per param. One
validatecall checks everything and returns a typed object. - Responses are templates or
render_json. There are no serializer classes. - No ORM. SQL is the source of truth, through crsql.
- Smaller surface. Runcobo has no asset pipeline, mailer or authentication generator. Bring the libraries you need.
Next: Installation, then the blog tutorial.