Changes in API from Cohttp version
roddyyaga opened this issue · comments
In the Cohttp version, there is a respond
function and body
type like this:
let to_body = function
| `String s -> Body.of_string s
| `Empty -> Body.empty
| `Json j -> j |> Yojson.Safe.to_string |> Body.of_string
let respond ?headers ?status body =
Response.make ?headers ?status ~body:(to_body body) () |> Lwt.return
Personally I thought that was a nice API, is there a reason it's been removed from the latest version?
Hi @roddyyaga ,
There are indeed some differences in the API compared to the cohttp version. One my reasoning for some changes was to move more of the response/body creation into opium_kernel (as opposed to opium) and have something that's easier to discover than poly variants. The current state of Body and Response look like this:
Body:
https://github.com/rgrinberg/opium/blob/29165400123c2d54da27d3e6edb3404374f532f9/opium_kernel/src/opium_kernel.mli#L41-L58
Response:
https://github.com/rgrinberg/opium/blob/29165400123c2d54da27d3e6edb3404374f532f9/opium_kernel/src/opium_kernel.mli#L121-L147
I felt that this would be easier for new users to discover than poly variants since this will be inside modules that they'd expect them to be in. I can see expanding the Response module to cover the other body types (stream is the only one that remains) which should bring this to par with the cohttp version.
Best,
Anurag