modification in code snippet

This commit is contained in:
Nishant Kumar
2024-03-22 18:26:19 +05:30
parent 816eae4b33
commit d0ec2c74d1
2 changed files with 75 additions and 288 deletions

View File

@ -11,7 +11,6 @@ class cCurlCodeGen {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
@ -19,11 +18,7 @@ int main() {
if(curl) {
""";
String kTemplateUrl = """
curl_easy_setopt(curl, CURLOPT_URL, "{{url}}");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
String kTemplateUrl = """\n curl_easy_setopt(curl, CURLOPT_URL, "{{url}}");
""";
String kTemplateBody = """
@ -54,24 +49,16 @@ int main() {
String kTemplateHeader = """
struct curl_slist *headers = NULL;
{% if headers %}{% for header, value in headers %}
headers = curl_slist_append(headers,"{{header}}: {{value}}");{% endfor %}
{% endif %}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
{% if headers %}{% for header, value in headers %} headers = curl_slist_append(headers,"{{header}}: {{value}}");\n {% endfor %}
{% endif %} curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
""";
String kTemplateQueryParam = """""";
String kTemplateRequest = """
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "{{method}}");
""";
String kTemplateRequest = """{% if method != "GET" and method != "POST" %}\n curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "{{method}}");{% endif %}""";
final String kTemplateEnd = """
{% if formdata %}curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);{% endif %}
res = curl_easy_perform(curl);
{% if formdata %}curl_mime_free(mime);{% endif %}
{% if headers %}curl_slist_free_all(headers);{% endif %}
{% if formdata %}curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);{% endif %}
res = curl_easy_perform(curl);{% if formdata %}\n curl_mime_free(mime);{% endif %}{% if headers %}\n curl_slist_free_all(headers);{% endif %}
}
curl_easy_cleanup(curl);
return 0;
@ -112,12 +99,12 @@ int main() {
);
var headersList = requestModel.enabledRequestHeaders;
if (headersList != null || requestModel.hasBody || requestModel.hasFormData) {
if (headersList != null || requestModel.hasBody || requestModel.hasTextData || requestModel.hasJsonData) {
var headers = requestModel.enabledHeadersMap;
if(requestModel.hasFormData){
headers.putIfAbsent("Content-Type", () => "multipart/form-data");
}
if (requestModel.hasJsonData || requestModel.hasTextData) {
// if (requestModel.hasFormData) {
// headers.putIfAbsent("Content-Type", () => "multipart/form-data");
// }
if (requestModel.hasTextData || requestModel.hasJsonData) {
headers.putIfAbsent(kHeaderContentType,
() => requestModel.requestBodyContentType.header);
}
@ -136,9 +123,10 @@ int main() {
hasBody = true;
var templateRawBody = jj.Template(kTemplateBody);
String Body = "";
if (requestBody != null) Body = requestBody.replaceAll('"', '\\"').replaceAll('\n', '\\n');
result += templateRawBody
.render({"body": Body});
if (requestBody != null) {
Body = requestBody.replaceAll('"', '\\"').replaceAll('\n', '\\n');
}
result += templateRawBody.render({"body": Body});
} else if (requestModel.hasFormData) {
hasBody = true;
var templateFormData = jj.Template(kTemplateFormData);
@ -156,9 +144,7 @@ int main() {
}
}
var headers = requestModel.enabledHeadersMap;
bool allow = headers.isNotEmpty ||
requestModel.hasJsonData ||
requestModel.hasTextData || requestModel.hasFormData;
bool allow = headers.isNotEmpty || requestModel.hasTextData || requestModel.hasJsonData;
var templateEnd = jj.Template(kTemplateEnd);
result += templateEnd.render({
"formdata": requestModel.hasFormData,

View File

@ -13,20 +13,13 @@ void main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -43,20 +36,13 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/country/data?code=US");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -73,20 +59,13 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/country/data?code=IND");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -103,20 +82,13 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -133,24 +105,17 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.github.com/repos/foss42/apidash");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.github.com/repos/foss42/apidash");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -168,24 +133,17 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.github.com/repos/foss42/apidash?raw=true");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.github.com/repos/foss42/apidash?raw=true");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -203,20 +161,13 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -233,24 +184,17 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.github.com/repos/foss42/apidash?raw=true");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.github.com/repos/foss42/apidash?raw=true");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -268,20 +212,13 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social?num=8700000&add_space=true");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -298,24 +235,17 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -336,24 +266,17 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social?num=8700000&digits=3");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social?num=8700000&digits=3");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -371,20 +294,13 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/humanize/social");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -403,20 +319,14 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "HEAD");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -433,20 +343,14 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "HEAD");
curl_easy_setopt(curl, CURLOPT_URL, "http://api.apidash.dev");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -465,28 +369,21 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/case/lower");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/case/lower");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: text/plain");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"text\": \"I LOVE Flutter\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -504,28 +401,21 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/case/lower");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/case/lower");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"text\": \"I LOVE Flutter\",\n\"flag\": null,\n\"male\": true,\n\"female\": false,\n\"no\": 1.2,\n\"arr\": [\"null\", \"true\", \"false\", null]\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -543,29 +433,22 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/case/lower");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/case/lower");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
headers = curl_slist_append(headers,"User-Agent: Test Agent");
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"text\": \"I LOVE Flutter\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -583,21 +466,12 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/form");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/form");
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
@ -616,11 +490,9 @@ int main() {
curl_mime_name(part, "times");
curl_mime_data(part, "3", CURL_ZERO_TERMINATED);
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
return 0;
@ -637,20 +509,14 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/form");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/form");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
headers = curl_slist_append(headers,"User-Agent: Test Agent");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
@ -671,7 +537,6 @@ int main() {
curl_mime_name(part, "times");
curl_mime_data(part, "3", CURL_ZERO_TERMINATED);
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
@ -692,21 +557,12 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/img");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/img");
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
@ -720,11 +576,9 @@ int main() {
curl_mime_name(part, "imfile");
curl_mime_filedata(part, "/Documents/up/1.png");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
return 0;
@ -741,21 +595,12 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/img");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/img");
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
@ -769,11 +614,9 @@ int main() {
curl_mime_name(part, "imfile");
curl_mime_filedata(part, "/Documents/up/1.png");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
return 0;
@ -790,21 +633,12 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/form?size=2&len=3");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/form?size=2&len=3");
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
@ -823,11 +657,9 @@ int main() {
curl_mime_name(part, "times");
curl_mime_data(part, "3", CURL_ZERO_TERMINATED);
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
return 0;
@ -844,21 +676,15 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/img?size=2&len=3");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.apidash.dev/io/img?size=2&len=3");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"User-Agent: Test Agent");
headers = curl_slist_append(headers,"Keep-Alive: true");
headers = curl_slist_append(headers,"Content-Type: multipart/form-data");
headers = curl_slist_append(headers,"User-Agent: Test Agent");
headers = curl_slist_append(headers,"Keep-Alive: true");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
@ -874,7 +700,6 @@ int main() {
curl_mime_name(part, "imfile");
curl_mime_filedata(part, "/Documents/up/1.png");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
@ -897,28 +722,22 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(curl, CURLOPT_URL, "https://reqres.in/api/users/2");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
curl_easy_setopt(curl, CURLOPT_URL, "https://reqres.in/api/users/2");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -938,28 +757,22 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_easy_setopt(curl, CURLOPT_URL, "https://reqres.in/api/users/2");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
curl_easy_setopt(curl, CURLOPT_URL, "https://reqres.in/api/users/2");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
@ -979,20 +792,14 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_easy_setopt(curl, CURLOPT_URL, "https://reqres.in/api/users/2");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return 0;
@ -1009,28 +816,22 @@ int main() {
#include <string.h>
#include <curl/curl.h>
int main() {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_easy_setopt(curl, CURLOPT_URL, "https://reqres.in/api/users/2");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
curl_easy_setopt(curl, CURLOPT_URL, "https://reqres.in/api/users/2");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers,"Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);