fetch
This commit is contained in:
parent
580e53d3bc
commit
98d0af014d
7 changed files with 132 additions and 57 deletions
18
examples/FetchExample/main.cpp
Normal file
18
examples/FetchExample/main.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import Crafter.CppDOM;
|
||||
import std;
|
||||
using namespace Crafter::CppDOMBindings;
|
||||
|
||||
int main(){
|
||||
void* body = GetElementById("body");
|
||||
SetInnerHTML(body, "<h1>Fetch Example</h1><p>Testing HTTP requests...</p>");
|
||||
|
||||
Fetch("https://httpbin.org/get", [body](std::string result){
|
||||
std::cout << "callback recieved2" << std::endl;
|
||||
if (!result.empty()) {
|
||||
SetInnerHTML(body, "<h1>Fetch Example</h1><p>Response: " + result + "</p>");
|
||||
} else {
|
||||
SetInnerHTML(body, "<h1>Fetch Example</h1><p>Failed to fetch data</p>");
|
||||
}
|
||||
FreeJs(body);
|
||||
});
|
||||
}
|
||||
17
examples/FetchExample/project.json
Normal file
17
examples/FetchExample/project.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "main",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "executable",
|
||||
"implementations": ["main"],
|
||||
"target": "wasm32-wasi",
|
||||
"debug" : true,
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-debug"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
1
examples/FetchExample/run.sh
Executable file
1
examples/FetchExample/run.sh
Executable file
|
|
@ -0,0 +1 @@
|
|||
caddy file-server --listen :8080 --root bin/executable
|
||||
Loading…
Add table
Add a link
Reference in a new issue