How to start a mist server
masterA mist server is initialized using a Builder pattern. You start with mist.new, configure it using various methods like bind, port, and with_ipv6, and finally call mist.start with a handler function. The handler function receives a Request(Connection) and must return a Response(ResponseData).
import mist
import gleam/http/request.{type Request}
import gleam/http/response.{type Response}
import mist.{type Connection, type ResponseData}
pub fn main() {
let assert Ok(_) =
fn(req: Request(Connection)) -> Response(ResponseData) {
// Your routing logic here
response.new(200) |> response.set_body(mist.Bytes(bytes_tree.new()))
}
|> mist.new()
|> mist.bind("localhost")
|> mist.port(4000)
|> mist.start()
// Keep the process alive
process.sleep_forever()
}