From 6b15c9e20c97814191426902448866182ae54c18 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Tue, 11 Nov 2025 00:25:24 +0100 Subject: [PATCH] fetch readme --- examples/FetchExample/README.md | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/FetchExample/README.md diff --git a/examples/FetchExample/README.md b/examples/FetchExample/README.md new file mode 100644 index 0000000..debb776 --- /dev/null +++ b/examples/FetchExample/README.md @@ -0,0 +1,42 @@ +# FetchExample + +This sample demonstrates how to use the Fetch API in Crafter.CppDOM to make HTTP requests. + +## Features + +- Shows how to perform HTTP GET requests +- Demonstrates asynchronous response handling +- Illustrates how to update the DOM with fetched data + +## Usage + +```cpp +import Crafter.CppDOM; +import std; +using namespace Crafter::CppDOMBindings; + +int main(){ + void* body = GetElementById("body"); + SetInnerHTML(body, "

Fetch Example

Testing HTTP requests...

"); + + Fetch("https://httpbin.org/get", [body](std::string result){ + if (!result.empty()) { + SetInnerHTML(body, "

Fetch Example

Response: " + result + "

"); + } else { + SetInnerHTML(body, "

Fetch Example

Failed to fetch data

"); + } + FreeJs(body); + }); +} +``` + +## Building and Running + +```bash +crafter-build build executable +run.sh +``` + +Then navigate to `http://localhost:8080/` in your browser. + +If caddy is not installed, you can use your favorite static file server instead. \ No newline at end of file