HTTP Server

REK has first-class support for building HTTP servers. The http module makes it easy to create web applications.

Basic Server

import http

let app = http.new()

app.get("/", fn(req, res) {
    res.text("Hello from REK!")
})

app.listen(3000)
log("Server running on port 3000")

Routing

Support for common HTTP methods: get, post, put, delete.

app.post("/users", fn(req, res) {
    // Handle user creation
    res.json({ "status": "created" })
})

Request Object

The req object contains information about the incoming request.

Response Object

The res object is used to send data back to the client.

app.get("/error", fn(req, res) {
    res.status(500).text("Something went wrong")
})