fermyon / spin-rust-sdk

Spin SDK for Rust
https://developer.fermyon.com/spin/v2/rust-components
Apache License 2.0
12 stars 12 forks source link

Rust SDK: add friendly constructor/builder for `OutgoingRequest` #24

Open itowlson opened 1 year ago

itowlson commented 1 year ago

Per https://github.com/fermyon/spin/blob/b45feb8e91afe5625a2de19e1904eec10ebbc936/examples/wasi-http-rust-streaming-outgoing-body/src/lib.rs#L99:

    let outbound_req = spin_sdk::http::OutgoingRequest::new(
        &spin_sdk::http::Method::Get,
        None,
        Some(&spin_sdk::http::Scheme::Https),
        Some("dioxus-test-ninaynoi.fermyon.app"),
        &spin_sdk::http::Fields::new(&[]),
    );

Could we add a constructor or builder that takes a URL, and maybe a Method instead of &Method? It feels a bit unwieldy right now (though users can always create their own wrappers).

lann commented 1 year ago

https://github.com/fermyon/spin/pull/1977

use spin_sdk::http::Request;
let resp: Response = spin_sdk::http::send(Request::get(
    "https://random-data-api.fermyon.app/animals/json",
)).await?;
itowlson commented 1 year ago

@lann I might be misunderstanding - we already had builders for Request, although your new ones are nicer for sure - this issue was specifically about OutgoingRequest. Are you saying to no longer use OutgoingRequest? (My specific interest was streaming request bodies.) Or is the idea that we could construct a Request with the friendly builder and then .into() it to get an OutgoingRequest?

lann commented 1 year ago

Ah no the linked PR doesn't help with streaming request bodies. The example you linked just streams the response body, and I think you can mix-n-match a non-streaming Request with a streaming IncomingResponse.

itowlson commented 1 year ago

I'm not explaining myself very well I fear.

I linked the example to try illustrate the third item not the first one, and was trying to clarify if fermyon/spin#1977 helps with said third one. My mention of streaming was only to explain why I (thought I) needed an OutgoingRequest rather than a Request.

Sorry for the confusion.