A simple HTTP web framework for Pony, inspired by Jennet and powered by Stallion.
hobby is beta quality software that will change frequently. Expect breaking changes. That said, you should feel comfortable using it in your projects.
- Install corral
corral add github.com/ponylang/hobby.git --version 0.3.0corral fetchto fetch your dependenciesuse "hobby"to include this packagecorral run -- ponycto compile your application
use hobby = "hobby"
use stallion = "stallion"
use lori = "lori"
actor Main
new create(env: Env) =>
let auth = lori.TCPListenAuth(env.root)
hobby.Application
.>get("/", {(ctx) =>
hobby.RequestHandler(consume ctx)
.respond(stallion.StatusOK, "Hello!")
} val)
.>get("/greet/:name", {(ctx) =>
let handler = hobby.RequestHandler(consume ctx)
try
let name = handler.param("name")?
handler.respond(stallion.StatusOK, "Hello, " + name + "!")
else
handler.respond(stallion.StatusBadRequest, "Bad Request")
end
} val)
.serve(auth, stallion.ServerConfig("localhost", "8080"), env.out)See the examples directory for more, including middleware usage. For a detailed walkthrough, read the Writing Middleware guide.