spiderfire icon indicating copy to clipboard operation
spiderfire copied to clipboard

HTTP Networking Module

Open Redfire75369 opened this issue 2 years ago • 5 comments

Issue

Spiderfire currently lacks a networking module, making it impossible to use this as a serverside runtime, and serve webpages for example. It is also unable to fetch data from web APIs. Implementing a networking module will be essential for spiderfire's usage.

Possible Solution

hyper or reqwest can be used to provide HTTP networking APIs in a module.

Redfire75369 avatar Oct 07 '21 16:10 Redfire75369

How do importing other files currently work in spiderfire?

I propose a syntax like

let request =  http.get("https://my.dopeapi.dev/get", {"headers": {"Authorization": "my_token"}});
console.log(request.response);

and we could also implement an HTTP handler for more efficient handling of multiple http requests

let handler = http.newHandler();
handler.get(...);
handler.delete(...);

I'd also recommend the ureq crate -- https://lib.rs/ureq

gimbling-away avatar Jan 02 '22 06:01 gimbling-away

Importing is currently along the lines of

import fs from "fs";
import {get} from "./http.js";

Both of those methods (directly sending a request) and creating a request handler/agent to request without passing the options every time are planned.

I was planning to use hyper, but I can definitely take a look at ureq. My main issue with ureq is probably the lack of an asynchronous API.

Redfire75369 avatar Jan 02 '22 11:01 Redfire75369