Add minimal support for a HTTP client in Yaksha

Bhathiya Perera

YAMA 0011 - Add minimal support for a HTTP client in Yaksha

  • Author(s): Bhathiya Perera
  • Status : 🟡

Summary

All programming languages provide a way to make HTTP requests. However, this is currently not available to Yaksha. This proposal aims to add minimal support for HTTP requests to Yaksha.

Design

We plan on using mongoose to implement this feature. Mongoose is a lightweight HTTP server written in C. It is easy to integrate. However, it’s license is GPL and users of http library will have to be aware of this.

Client

Simple HTTP client will use following structure. This will be placed in a separate module called http/client.yaka.

# Mongoose mgr data structure
@nativedefine("struct mg_mgr")
stuct MongooseMgr:
    pass

# Mongoose connection data structure
@nativedefine("struct mg_connection")
struct MongooseCon:
    pass

# HTTP client data structure using above 2 structs
struct HttpClient:
    mgr: MongooseMgr
    nc: Ptr[MongooseCon]
    success: bool

def http_client(url: sr) -> HttpClient:
    pass  # placeholder

def request(method: sr, url: sr, data: sr, callback: Function[..]) -> HttpRequest:
    pass  # placeholder

Usage of the client will be as follows:

import http.client as client

def callback(...): # placeholder
    pass

def main() -> int:
    cl = client.http_client("http://localhost:8080")
    cl.request("GET", "/api/v1/users", "", callback)
    defer free_http_client(cl)
    return 0

Required changes to Yaksha ecosystem

  • Implement ability to support fixed sized arrays in Yaksha (parser, compiler, etc).
  • Implement ability in YakshaLisp to execute programs and access output.
  • Implement ability in carpntr to use YakshaLisp to build programs. (Either use program execution ability or use make/cmake to build programs)
  • Implement ability in YakshaLisp to detect platform and use appropriate build system.
  • CI - Add ability to build Yaksha release on supported platforms using github actions. (Instead of cross compiling)
  • Remove hammer and just use cmake to build Yaksha.
  • Update build and other scripts accordingly.

Third party libraries to be included

  • mongoose - for making HTTP requests
  • mbedtls - for TLS support
  • reproc - for executing programs