<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I now have a working binding for libcurl that can do a GET and I am stuck trying to find a good example of how to allocate a mercury string to hand back into Mercury land.</div><div class="">I have the same code from here: <a href="https://curl.se/libcurl/c/getinmemory.html" class="">https://curl.se/libcurl/c/getinmemory.html</a></div><div class=""><br class=""></div><div class="">After a call succeeds, here is how I am currently handling to curl response:</div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""> if (CURLE_OK == res) {<br class=""> printf(""* %lu bytes retrieved\\n"", (unsigned long)chunk.size);<br class=""> long HttpStatus;<br class=""> curl_easy_getinfo(ch, CURLINFO_RESPONSE_CODE, &HttpStatus);<br class=""><b class=""> Response = makeResponse((int)HttpStatus);<br class=""></b> }<br class=""> else {<br class=""> Response = makeError(1, curl_easy_strerror(res));<br class=""> }</font></div><div class=""><br class=""></div><div class="">The line in bold, here is where I need to be able to create a string with the data from chunk.memory, for the number of bytes received, chunk.size, this is where I am unsure how to continue. The makeResponse() code is:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">:- func make_response(int::in)<br class=""> = (io.res(curl_response)::out) is det.<br class=""><br class="">make_response(HttpStatus)<br class=""> = ok(curl_response(HttpStatus, "Data!", [])).<br class=""><br class="">:- pragma foreign_export("C", make_response(in)<br class=""> = (out), "makeResponse").</font></div><div class=""><br class=""></div><div class="">with:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">:- type curl_header ---> curl_header(string, string).<br class="">:- type curl_response<br class=""> ---> curl_response(<br class=""> status :: int,<br class=""> content :: string,<br class=""> headers :: list(curl_header)<br class=""> ).</font></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I am also unsure of how to map a C "long"; the curl call `curl_easy_getinfo(ch, CURLINFO_RESPONSE_CODE, &longVal);` expects a pointer to a long, which I am currently then casting to an integer given the known range of HTTP status codes, but in general, if I wanted to pass that into a mercury function, what type do I use given I am on M1 arm64, the C specs only state 'minimum width' of 32, so int32 springs to mind but is this the correct assumption ?</div><div class=""><br class=""></div><div class="">The final intention is to be able to have enough HTTP support available so that I can use the average API out there, GET/POST/PUT/FETCH/OPTIONS, with a view to implementing support layer for using my SOLID POD from a Mercury command line application.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">Sean.</div><div class=""><br class=""></div></body></html>