fetch
This commit is contained in:
parent
580e53d3bc
commit
98d0af014d
7 changed files with 132 additions and 57 deletions
28
README.md
28
README.md
|
|
@ -78,4 +78,30 @@ int main(){
|
|||
|
||||
Save and close, then run ``crafter-build build executable && caddy file-server --listen :8080 --root bin/executable``. if you have caddy installed, if not use your favorite static file server instead. Now you can open the browser at ``http://localhost:8080`` and ``Hello World!`` will appear in the browser.
|
||||
|
||||
This sample can also be viewed in the [HelloElement example](https://forgejo.catcrafts.net/Catcrafts/Crafter.CppDOM/src/branch/master/examples)
|
||||
This sample can also be viewed in the [HelloElement example](https://forgejo.catcrafts.net/Catcrafts/Crafter.CppDOM/src/branch/master/examples)
|
||||
|
||||
# Fetch Functionality
|
||||
|
||||
The library now includes support for making HTTP requests using the `fetch` function:
|
||||
|
||||
```cpp
|
||||
import Crafter.CppDOM;
|
||||
using namespace Crafter::CppDOMBindings;
|
||||
|
||||
int main(){
|
||||
// Make a POST request with body data
|
||||
std::string result = Fetch("https://httpbin.org/post", "{\"test\": \"data\"}");
|
||||
|
||||
// Or make a request without body data
|
||||
std::string result = Fetch("https://httpbin.org/get");
|
||||
|
||||
// Handle the response
|
||||
if (!result.empty()) {
|
||||
// Process the response
|
||||
HtmlElementView body("body");
|
||||
body.SetInnerHTML("Response: " + result);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This feature allows you to make HTTP requests directly from C++ code running in WebAssembly, which can be useful for communicating with APIs or backend services.
|
||||
Loading…
Add table
Add a link
Reference in a new issue