Your First App
The smallest Ticket app is one route, one view and a layout. It's the same app as Ticket's examples/hello.
The project file
Make a folder next to your Ticket checkout with a polar.toml. The dependency makes Ticket.* modules available, and the launcher line makes polar run serve your app over HTTP.
[project]
name = "hello"
hosts = ["Node"]
[dependencies]
ticket = { path = "../ticket" }
[run]
launcher = "ticket"
options = { port = 3000 }
A layout
A layout is a plain view that takes the page's Html. Views live in a views zone, and the module has to use Ticket.Html.
module Layout
uses
Ticket.Html
views
app(title: String, body: Html)
<html>
<head>
<title>{title}</title>
</head>
<body>{body}</body>
</html>
exports
app
A view
module Pages
uses
Ticket.Html
views
home(name: String)
<h1>Hello from {name}</h1>
exports
home
The router
The app's main module exports router(request: Request) -> Option<Response>. Returning None means no route matched, and the launcher answers 404. Here it's written by hand. Real apps let a routes zone generate it.
module Main
uses
Std.Http
Std.Option
Layout
Pages
Ticket.Html
Ticket.Response
hosts
Node
functions
router(request: Request) -> Option<Response> {
if request.path == "/" {
Some(Response.html(200, Html.document(Layout.app("Hello", Pages.home("Ticket")))))
} else {
None
}
}
exports
router
Run it
$ polar run
hello is listening on http://127.0.0.1:3000
GET / -> 200 <!doctype html><html><head><title>Hello</title></head><body><h1>Hello from Ticket</h1></body></html>
GET /nope -> 404 {"error":"not found"}
Tip: polar build && polar start does the same in two steps, and leaves a dist/ folder you can run on its own.
Coming soon: ticket new hello will write this skeleton for you, and ticket server will run it. Both are being built now.