Skip to content

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 ​

LuckyRuncobo
class Posts::Show < ApiActionclass Posts::ShowPost < Blog::BaseAction
get "/posts/:post_id" do ... endget "/posts/:id" + call do ... end
Route params as methods (post_id)Contract fields: validate(ShowPostContract).id
params.from_json, operation paramsOne contract for path, query and body
before require_sign_in / after / skipbefore / after / skip — the same
A pipe returns continueA filter returns anything; byebye halts (continue also works)
json(...), serializersrender_json(...), or Jbuilder templates
HTML pages and componentsWater templates, layouts and partials
Avram models and query objectsNamed SQL queries → a typed store
SaveOperation validationsContracts for input; constraints in SQL for data
Avram migrations (Crystal DSL)Plain SQL migrations
lucky devbin/cobo dev
lucky routesbin/cobo routes
lucky db.migratebin/cobo db migrate

An action ​

crystal
# Lucky
class Api::Posts::Show < ApiAction
  get "/api/posts/:post_id" do
    post = PostQuery.find(post_id)
    json PostSerializer.new(post)
  end
end
crystal
# 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
end
src/actions/posts/show_post_contract.cr
crystal
class Posts::ShowPostContract < RequestValidation::Contract
  schema do
    required :id, Int64
  end
end
src/actions/posts/show_post.jbuilder
crystal
json.id post.id
json.title post.title

The 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 ​

crystal
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
end

The 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:

db/queries/posts.sql
sql
-- name: ListPublishedPosts :many
SELECT id, title FROM posts WHERE published_at IS NOT NULL ORDER BY published_at DESC;
crystal
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 validate call 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.

Released under the MIT License.