forked from fermyon/spin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fermyon#1977 from lann/enhance-http-types
rust: Add some convenience methods/impls to http types
- Loading branch information
Showing
8 changed files
with
66 additions
and
93 deletions.
There are no files selected for viewing
53 changes: 0 additions & 53 deletions
53
examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 8 additions & 12 deletions
20
examples/http-rust-outbound-http/outbound-http-to-same-app/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
use anyhow::Result; | ||
use spin_sdk::{ | ||
http::{IntoResponse, Request}, | ||
http::{IntoResponse, Request, Response}, | ||
http_component, | ||
}; | ||
|
||
/// Send an HTTP request and return the response. | ||
#[http_component] | ||
async fn send_outbound(_req: Request) -> Result<impl IntoResponse> { | ||
let mut res: http::Response<String> = spin_sdk::http::send( | ||
http::Request::builder() | ||
.method("GET") | ||
.uri("/hello") | ||
.body(())?, | ||
) | ||
.await?; | ||
res.headers_mut() | ||
.insert("spin-component", "rust-outbound-http".try_into()?); | ||
println!("{:?}", res); | ||
Ok(res) | ||
let resp: Response = spin_sdk::http::send(Request::get("/hello")).await?; | ||
let resp = resp | ||
.into_builder() | ||
.header("spin-component", "rust-outbound-http") | ||
.build(); | ||
println!("{resp:?}"); | ||
Ok(resp) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 10 additions & 11 deletions
21
examples/http-rust-outbound-http/outbound-http/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
use anyhow::Result; | ||
use spin_sdk::{ | ||
http::{IntoResponse, Request}, | ||
http::{IntoResponse, Request, Response}, | ||
http_component, | ||
}; | ||
|
||
/// Send an HTTP request and return the response. | ||
#[http_component] | ||
async fn send_outbound(_req: Request) -> Result<impl IntoResponse> { | ||
let mut res: http::Response<String> = spin_sdk::http::send( | ||
http::Request::builder() | ||
.method("GET") | ||
.uri("https://random-data-api.fermyon.app/animals/json") | ||
.body(())?, | ||
) | ||
let resp: Response = spin_sdk::http::send(Request::get( | ||
"https://random-data-api.fermyon.app/animals/json", | ||
)) | ||
.await?; | ||
res.headers_mut() | ||
.insert("spin-component", "rust-outbound-http".try_into()?); | ||
println!("{:?}", res); | ||
Ok(res) | ||
let resp = resp | ||
.into_builder() | ||
.header("spin-component", "rust-outbound-http") | ||
.build(); | ||
println!("{resp:?}"); | ||
Ok(resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters