Skip to main content

Creating a HTTP Server

In duck you can easily create a HttpServer using the std::http module.

tip

You can create a project using dargo new. Dargo can be installed here // TODO: insert link here

src/main.duck
use std::web::{HttpServer, Req, Res};

fn main() {
// creating a new http server
const http_server = std::web::HttpServer::new(.verbose);

// adding a GET handler on /config
http_server.handle("GET /config", fn (req: Req, res: &mut Res) {
res.json({
version: "1.0",
metadata: {
authors: ["John", "Bert"],
}
});
});

// listening on port 8080
http_server.listen(":8080");
}