An HTTP server framework for Pony, powered by Stallion. Features include route parameter extraction, middleware, route groups, static file serving, streaming responses, and actor-per-request async handlers.
hobby is beta quality software that will change frequently. Expect breaking changes. That said, you should feel comfortable using it in your projects.
- Requires ponyc 0.63.1 or later
- Install corral
corral add github.com/ponylang/hobby.git --version 0.7.0corral fetchto fetch your dependenciesuse "hobby"to include this packagecorral run -- ponycto compile your application
Note: The ssl transitive dependency requires a C SSL library to be installed. Please see the ssl installation instructions for more information.
use hobby = "hobby"
use stallion = "stallion"
use lori = "lori"
actor Main is hobby.ServerNotify
let _env: Env
new create(env: Env) =>
_env = env
let auth = lori.TCPListenAuth(env.root)
let app = 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)
match app.build()
| let built: hobby.BuiltApplication =>
hobby.Server(auth, built, this
where host = "localhost", port = "8080")
| let err: hobby.ConfigError =>
env.err.print(err.message)
end
be listening(server: hobby.Server, host: String, service: String) =>
_env.out.print("Listening on " + host + ":" + service)See the examples directory for more, including interceptor usage. For a detailed walkthrough, read the Writing Request Interceptors guide.