Your First App
Hello World
The simplest Bolt app:
load "bolt.ring"
new Bolt() { $bolt.send("Hello, World!") }A Real App
A more complete example with routing, params, and JSON:
load "bolt.ring"
new Bolt() {
port = 3000
@get("/", func {
$bolt.send("Hello from Bolt!")
})
@get("/users/:id", func {
$bolt.json([
:id = $bolt.param("id"),
:name = "User " + $bolt.param("id")
])
})
where("id", "[0-9]+")
@post("/users", func {
data = $bolt.jsonBody()
$bolt.jsonWithStatus(201, [:created = true, :data = data])
})
}Run it:
ring app.ringWhat’s Happening
load "bolt.ring"— loads the Bolt frameworknew Bolt() { ... }— creates a new server instanceport = 3000— sets the listening port@get("/", func { ... })— defines a GET route$bolt.send(...)— sends a text response$bolt.json(...)— sends a JSON response$bolt.param("id")— reads a URL parameter$bolt.jsonBody()— parses the request body as JSONwhere("id", "[0-9]+")— constrains the:idparam to digits