This is one of the main use cases for the language so far and i cannot figure out how to do something as simple as read the request body for https://github.com/roc-lang/basic-webserver/tree/main . Anyone have any experience with a simple example? I can find none doing anything meaningful with a req.body
I wrote up an article which touches on this a little https://lukewilliamboswell.github.io/roc-htmx-demo/
In there I parse the request body, something like,
(Post, ["login"]) ->
params = parseFormUrlEncoded (parseBody req)
Here is the link to parseBody
https://github.com/lukewilliamboswell/lukewilliamboswell.github.io/blob/06fe7cc745213e5302d35ef29a513021eb67905a/content/roc-htmx-demo/main.roc#L713
Personally I really dislike that API and I would like to change it. Also, the docs could be soo much clearer. If you have any ideas please let me know, I might spend some time on this later today.
@Gregory Walker just looking at making an example for this, do you have any good ideas in mind? what is something meaningful we could do here? Maybe parse a JSON thing?
Luke Boswell said:
Gregory Walker just looking at making an example for this, do you have any good ideas in mind? what is something meaningful we could do here? Maybe parse a JSON thing?
Thank you, i was at a point where i'd have been grateful to figure out how i could print to stdout the request body. What i was trying to do yesterday was save the json document to postgres (in this case, i wouldn't know the form of the json ahead of time). I think most users would just like to use the fields in the request body (decode the json into a recod type)
Last updated: Jul 05 2025 at 12:14 UTC