I am porting a project previously based on a synchronous nethttpd server to Opium.
I’d first like to thank @rgrinberg for Opium, which is so much easier to set up than nethttpd :). Since I am not much used to event programming or Lwt, I have some questions.
First question: When receiving e.g. a POST request with a body, the body seems to come as a
string Lwt_stream.t. Is there a “good way” to work with such body ? I could come with two ways, both using
let body = req.body |> Cohttp_lwt.Body.to_string |> Lwt_main.run ... use body variable
( match%lwt req.body |> Cohttp_lwt.Body.to_string >|= Yojson.Safe.from_string >|= my_type_of_yojson with | Ok res -> Lwt.return "body decoded" | Error e -> Lwt.return "bad body" ) |> Lwt_main.run
Second question: the web server provides an interface to a kind of simulator, that is an object that is not designed to be accessed concurrently. Will Mutex be enough to deal with this, or is there anything else i should know ?
- Third question (altough I guess I would eventually find out): I am using my own command line arguments, so I don’t use Opium’s built in. I did not see an easy way to pass e.g. the debug argument for the Opium App, is there one ?