roc/examples/webserver/echo.roc
Agus Zubiaga 8dedd9f03c
New app header syntax
Implements the new app header syntax as discussed in Zulip [1].

    app [main] {
	cli: platform "../platform/main.roc",
	json: "../json/main.roc"
    }

Old headers still parse and are automatically upgraded to the new
syntax by the formatter.

[1] 418444862
2024-05-01 10:49:01 -03:00

19 lines
702 B
Text

app [main] { pf: platform "https://github.com/roc-lang/basic-webserver/releases/download/0.1/dCL3KsovvV-8A5D_W_0X_abynkcRcoAngsgF0xtvQsk.tar.br" }
import pf.Stdout
import pf.Task exposing [Task]
import pf.Http exposing [Request, Response]
import pf.Utc
main : Request -> Task Response []
main = \req ->
# Log request date, method and url
date <- Utc.now |> Task.map Utc.toIso8601Str |> Task.await
{} <- Stdout.line "$(date) $(Http.methodToStr req.method) $(req.url)" |> Task.await
# Respond with request body
when req.body is
EmptyBody -> Task.ok { status: 200, headers: [], body: [] }
Body internal -> Task.ok { status: 200, headers: [], body: internal.body }