Code Monkey home page Code Monkey logo

fido's Introduction

Fido

Fido provides JS Fetch 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.

make fido

Running with Node.js (Mostly for testing)

node fido

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.

fido's People

Contributors

phoenixpinpoint avatar

Stargazers

timelyportfolio avatar Matt Mueller avatar

Watchers

timelyportfolio avatar  avatar

Forkers

gismo-stack

fido's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.