Skip to content

Getting Started

1.Init a Crystal project.

crystal init app demo && cd demo

2.Add the dependency to your shard.yml and run shards install.

dependencies:
  runcobo:
    github: runcobo/runcobo

3.Write down the following code in src/demo.cr.

require "runcobo"

class Api::V1::Add < BaseAction
  get "/api/v1/add"
  query NamedTuple(a: Int32, b: Int32)

  call do
    sum = params[:a] + params[:b]
    render_plain sum.to_s
  end
end

Runcobo.start

4.Run server.

crystal src/demo.cr

5.Send request.

curl "http://0.0.0.0:3000/api/v1/add?a=1&b=2"

6.Auto restart server.

# Use nodemon to watch file changed and auto restart server.
sudo npm install -g nodemon
nodemon -e "cr,water,jbuilder,yml" --exec "crystal run" src/demo.cr