Skip to content

Commit 06528c5

Browse files
authored
Merge pull request #1887 from fermyon/rust-sdk-improvements
Rust SDK http handler macro improvements
2 parents 57b004c + e7d8a17 commit 06528c5

File tree

97 files changed

+2616
-1047
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2616
-1047
lines changed

Cargo.lock

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const RUST_HTTP_INTEGRATION_ENV_TEST: &str = "tests/http/headers-env-routes-test
1212
const RUST_HTTP_VAULT_CONFIG_TEST: &str = "tests/http/vault-config-test";
1313
const RUST_OUTBOUND_REDIS_INTEGRATION_TEST: &str = "tests/outbound-redis/http-rust-outbound-redis";
1414
const TIMER_TRIGGER_INTEGRATION_TEST: &str = "examples/spin-timer/app-example";
15-
const WASI_HTTP_INTEGRATION_TEST: &str = "examples/wasi-http-rust-async";
15+
const WASI_HTTP_INTEGRATION_TEST: &str = "examples/wasi-http-rust-streaming-outgoing-body";
1616

1717
fn main() {
1818
// Extract environment information to be passed to plugins.

examples/config-rust/Cargo.lock

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/config-rust/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ version = "0.1.0"
44
edition = "2021"
55

66
[lib]
7-
crate-type = [ "cdylib" ]
7+
crate-type = ["cdylib"]
88

99
[dependencies]
1010
# Useful crate to handle errors.
1111
anyhow = "1"
12-
# Crate to simplify working with bytes.
13-
bytes = "1"
14-
# General-purpose crate with common HTTP types.
15-
http = "0.2"
1612
# The Spin SDK.
1713
spin-sdk = { path = "../../sdk/rust" }
18-
[workspace]
14+
[workspace]

examples/config-rust/src/lib.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use anyhow::Result;
21
use spin_sdk::{
32
config,
43
http::{Request, Response},
@@ -7,17 +6,11 @@ use spin_sdk::{
76

87
/// This endpoint returns the config value specified by key.
98
#[http_component]
10-
fn get(req: Request) -> Result<Response> {
11-
let path = req.uri().path();
12-
13-
if path.contains("dotenv") {
9+
fn get(req: Request) -> anyhow::Result<Response> {
10+
if req.uri.contains("dotenv") {
1411
let val = config::get("dotenv").expect("Failed to acquire dotenv from spin.toml");
15-
return Ok(http::Response::builder()
16-
.status(200)
17-
.body(Some(val.into()))?);
12+
return Ok(Response::new(200, val));
1813
}
1914
let val = format!("message: {}", config::get("message")?);
20-
Ok(http::Response::builder()
21-
.status(200)
22-
.body(Some(val.into()))?)
15+
Ok(Response::new(200, val))
2316
}

examples/http-rust-outbound-http/http-hello/Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/http-rust-outbound-http/http-hello/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ crate-type = ["cdylib"]
99
[dependencies]
1010
# Useful crate to handle errors.
1111
anyhow = "1"
12-
# Crate to simplify working with bytes.
13-
bytes = "1"
1412
# General-purpose crate with common HTTP types.
1513
http = "0.2"
1614
# The Spin SDK.
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
use anyhow::Result;
2-
use spin_sdk::{
3-
http::{Request, Response},
4-
http_component,
5-
};
2+
use spin_sdk::http_component;
63

74
/// A simple Spin HTTP component.
85
#[http_component]
9-
fn hello_world(_req: Request) -> Result<Response> {
6+
fn hello_world(_req: http::Request<()>) -> Result<http::Response<&'static str>> {
107
Ok(http::Response::builder()
118
.status(200)
12-
.header("foo", "bar")
13-
.body(Some("Hello, Fermyon!\n".into()))?)
9+
.body("Hello, Fermyon!\n")?)
1410
}

examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/http-rust-outbound-http/outbound-http-to-same-app/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ crate-type = ["cdylib"]
1010
# Useful crate to handle errors.
1111
anyhow = "1"
1212
# Crate to simplify working with bytes.
13-
bytes = "1"
14-
# General-purpose crate with common HTTP types.
1513
http = "0.2"
1614
# The Spin SDK.
1715
spin-sdk = { path = "../../../sdk/rust" }

0 commit comments

Comments
 (0)