Skip to content

Fido provides JS Fetch and Libcurl API bindings in C for use in WASM and Native Applications. Additionally Fido provides a simple Header, Request and, Response API

License

Notifications You must be signed in to change notification settings

phoenixpinpoint/fido

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fido

Fido provides JS Fetch and libcurl API bindings in C for use in WASM. Additionally Fido provides a simple Header, Request and, Response API.

Installation & Running

clibs Installation

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>

manual Installation

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

compilation and testing

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

Use

Simple GET

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;
}

Simple POST

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;
}

Additional Docs

All Documents are on this main repo so check out the other .md files.

About

Fido provides JS Fetch and Libcurl API bindings in C for use in WASM and Native Applications. Additionally Fido provides a simple Header, Request and, Response API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published