Stream: beginners

Topic: Read request body from basic web server


view this post on Zulip Gregory Walker (Jan 18 2024 at 23:18):

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

view this post on Zulip Luke Boswell (Jan 18 2024 at 23:25):

I wrote up an article which touches on this a little https://lukewilliamboswell.github.io/roc-htmx-demo/

view this post on Zulip Luke Boswell (Jan 18 2024 at 23:26):

In there I parse the request body, something like,

(Post, ["login"]) ->

            params = parseFormUrlEncoded (parseBody req)

view this post on Zulip Luke Boswell (Jan 18 2024 at 23:27):

Here is the link to parseBody
https://github.com/lukewilliamboswell/lukewilliamboswell.github.io/blob/06fe7cc745213e5302d35ef29a513021eb67905a/content/roc-htmx-demo/main.roc#L713

view this post on Zulip Luke Boswell (Jan 18 2024 at 23:29):

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.

view this post on Zulip Luke Boswell (Jan 18 2024 at 23:51):

@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?

view this post on Zulip Gregory Walker (Jan 19 2024 at 13:37):

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