freenet / freenet-core

Declare your digital independence
https://freenet.org/
Apache License 2.0
2.27k stars 78 forks source link

create a hight level api for freenet-core #1031

Open gogo2464 opened 7 months ago

gogo2464 commented 7 months ago

it is currently complicated to do GET/UPDATE/SUBSCRIBE requests in freenet library.

For example, fdev had to reimplement everything https://github.com/freenet/freenet-core/blob/main/crates/fdev/src/main.rs#L58

I suggest to exposed a struct to do:

I could put it in the lib.rs file https://github.com/freenet/freenet-stdlib/blob/main/rust/src/lib.rs

sanity commented 7 months ago

I think it belongs in the client_api module, perhaps for now in a client_api.simple module.

So something like:

let api = client_api.simple.API::new(ws_port);
let contract_state : Vec<u8> = api.get(contract_address).await;

Would appreciate @iduartgomez's input also.

gogo2464 commented 7 months ago

I started to implement it.

I love the concept of exposing minimal api. The issue is it sounds a windows driver wrapper philosophy. We should expose only the required and let everything else in private.

We may let folders as

gogo2464 commented 7 months ago

I suggest for a final version to do:

At this moment we may merge my current pr. Ready for a review.

gogo2464 commented 7 months ago

already usable with:

use freenet::client_api::simple::API;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    let mut api = API::new(50509);
    let out = api.update(String::from("lftMopswnMBotiZflwjYvuGCWbsileTEruGllHmLnOAWp"), vec![1, 2, 3]).await;
}

the value of out should be Ok().

gogo2464 commented 5 months ago

I created a draft pr to discuss of the template https://github.com/freenet/freenet-core/pull/1032 could you check it out and tell me what to improove or not?

gogo2464 commented 5 months ago

Another idea could be to simply expose the fdev commands as a public crate.

gogo2464 commented 4 months ago

@sanity I suggest to expose fdev commands instead of https://github.com/freenet/freenet-core/pull/1032. Can I do it please?