A simple scripting language in C++
Ferenc Szontágh
2025-04-19 3c645799476e526b04e13f648cd30643c1f39112
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# CURL + JSON Feature Test
# GET request
string $url = "https://jsonplaceholder.typicode.com/todos/1";
string $resp = curlGet($url);
printnl("GET raw: ", $resp);
object $data = json_decode($resp);
printnl("ID: ", $data->id, " Title: ", $data->title, " Completed: ", $data->completed);
 
# POST request
string $postUrl = "https://jsonplaceholder.typicode.com/posts";
object $payload = {
    string title: "foo",
    string body: "bar",
    int userId: 1
};
string $postData = json_encode($payload);
printnl("POST data: ", $postData);
string $postResp = curlPost($postUrl, $postData);
printnl("POST raw: ", $postResp);
object $postJson = json_decode($postResp);
// The response from JSONPlaceholder includes only the new id
printnl("POST ID: ", $postJson->id);
// --- GET with options ---
printnl("GET with options (timeout=5, follow_redirects, Accept header):");
string $optGet = curlGet($url, {
    timeout: 5,
    follow_redirects: true,
    headers: { Accept: "application/json" }
});
printnl($optGet);
// --- POST with options ---
printnl("POST with options (timeout=5, follow_redirects, X_Test header):");
string $optPost = curlPost($postUrl, $postData, {
    timeout: 5,
    follow_redirects: true,
    headers: { X_Test: "CustomValue" }
});
printnl($optPost);