Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
itowlson opened this issue Oct 26, 2023 · 4 comments
Open

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

itowlson opened this issue Oct 26, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@itowlson
Copy link
Contributor

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
Copy link
Contributor

lann commented Oct 27, 2023

fermyon/spin#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
Copy link
Contributor Author

@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
Copy link
Contributor

lann commented Oct 29, 2023

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
Copy link
Contributor Author

I'm not explaining myself very well I fear.

  • I want to stream request bodies.
  • To do this, I need an OutgoingRequest.
  • The constructor for OutgoingRequest is not terribly friendly.

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.

@vdice vdice added the enhancement New feature or request label Nov 8, 2023
@itowlson itowlson transferred this issue from fermyon/spin Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 🔖 Backlog
Development

No branches or pull requests

3 participants