Fido provides JS Fetch and libcurl API bindings in C for use in WASM. Additionally Fido provides a simple Header, Request and, Response API.
Installing Fido is simple with clibs. This section assumes you have the deps folder added to your includ path.
clib install phoenixpinpoint/fido
Somewhere in your GCC Makefile/Buildpath:
-Ideps
In your C files:
#include <fido/fido.h>
Although not recommended it is possible to install Fido without clibs. The general idea is below but mileage may vary.
#Create Deps Folder
mkdir deps
cd deps
#Add Deps and Fido
git clone https://github.com/clibs/buffer.git
git clone https://github.com/phoenixpinpoint/fido.git
#Update compiler
gcc ..-Ideps..-Ideps/fido/src
This section only applies for the project as a standalone. Compiling Fido as a standalone project with emscripten.
- Note: If you are running WASM/Emscripten tests you MUST be using a node version that supports the Fetch API.
make test
In this example we make a simple GET to a Web Page.
#include <fido/fido.h>
int main()
{
//Note if all macros are left intact you can remove FIDO_
FIDO_HTTP_REQUEST *req = FIDO_CREATE_HTTP_REQUEST("https://google.com", NULL, NULL);
FIDO_HTTP_RESPONSE *res = FIDO_GET(req);
//If the server response with 200 OK
if(res->response_code == 200)
{
printf("BODY: %s\n", res->body);
}
else {
printf("Some Error Occured.\n");
}
return 0;
}
In this example we make a simple POST to a Web Page.
#include <fido/fido.h>
int main()
{
//Note if all macros are left intact you can remove FIDO_
FIDO_HEADER *contentType = FIDO_CREATE_HEADER("Content-Type", "application/json");
FIDO_HEADERLIST *headers = FIDO_CREATE_HEADER_LIST();
FIDO_ADD_HEADER(headers, contentType);
FIDO_HTTP_REQUEST *req = FIDO_CREATE_HTTP_REQUEST("https://example.com", headers, "{\"TEST\":\"VALUE\"}");
FIDO_HTTP_RESPONSE *res = FIDO_POST(req);
//If the server response with 200 OK
if(res->response_code == 200)
{
printf("BODY: %s\n", res->body);
}
else {
printf("Some Error Occured.\n");
}
return 0;
}
All Documents are on this main repo so check out the other .md files.