23 const std::string& query_function,
24 const std::initializer_list<std::string>& extra_args ={
30 const std::string url =
"https://query.openkim.org/api/" + query_function;
33 std::string post_data;
36 for (
auto& kv : extra_args) {
38 if (!post_data.empty()) {
48 curl_global_init(CURL_GLOBAL_DEFAULT);
49 CURL* curl_handle = curl_easy_init();
51 curl_global_cleanup();
52 return "Error: Failed to initialize libcurl!";
55 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
56 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
59 curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
60 curl_easy_setopt(curl_handle, CURLOPT_POST, 1L);
61 curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, post_data.c_str());
62 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION,
write_callback);
63 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &response);
66 CURLcode res = curl_easy_perform(curl_handle);
67 if (res != CURLE_OK) {
68 response = std::string(
"curl error: ") + curl_easy_strerror(res);
72 curl_easy_cleanup(curl_handle);
73 curl_global_cleanup();