Skip to content

Commit 9b7648e

Browse files
committed
Fix duplicate samples
Signed-off-by: itowlson <[email protected]>
1 parent d44e19b commit 9b7648e

File tree

9 files changed

+41
-37
lines changed

9 files changed

+41
-37
lines changed

examples/http-rust/src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
use spin_sdk::http::{IntoResponse, Json, Response};
1+
use spin_sdk::http::{IntoResponse, Response};
22
use spin_sdk::http_component;
33

4-
#[derive(serde::Deserialize, Debug)]
5-
struct Greeted {
6-
name: String,
7-
}
8-
94
/// A simple Spin HTTP component.
105
#[http_component]
11-
fn hello_world(req: http::Request<Json<Greeted>>) -> anyhow::Result<impl IntoResponse> {
12-
Ok(Response::new(200, format!("Hello, {}", req.body().name)))
6+
fn hello_world(_req: http::Request<()>) -> anyhow::Result<impl IntoResponse> {
7+
Ok(Response::new(200, "Hello, world!"))
138
}
File renamed without changes.

examples/wasi-http-rust/Cargo.lock renamed to examples/json-http-rust/Cargo.lock

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

examples/wasi-http-rust/Cargo.toml renamed to examples/json-http-rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "wasi-http-rust"
2+
name = "json-http-rust"
33
version = "0.1.0"
44
edition = "2021"
55

examples/json-http-rust/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Automatically deserializing JSON request bodies in Rust HTTP
2+
3+
This sample shows using the `http::Request<Json<T>>` request type to accept JSON and automatically deserialize it into a Rust struct that implements `serde::Deserialize`.
4+
5+
To test it, run `spin up --build` and then POST to localhost:3000 e.g.:
6+
7+
```
8+
curl -X POST -d '{"name": "Vyvyan"}' localhost:3000
9+
```

examples/json-http-rust/spin.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
authors = ["Fermyon Engineering <[email protected]>"]
5+
description = "An application which parses a JSON POST body."
6+
name = "json-http-rust"
7+
version = "1.0.0"
8+
9+
[[trigger.http]]
10+
route = "/..."
11+
component = "json-demo"
12+
13+
[component.json-demo]
14+
source = "target/wasm32-wasi/release/json_http_rust.wasm"
15+
description = "Parses 'name' from the POST body and responds using it."
16+
[component.json-demo.build]
17+
command = "cargo build --target wasm32-wasi --release"
18+
watch = ["src/**/*.rs", "Cargo.toml"]
File renamed without changes.

examples/wasi-http-rust/spin.toml

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)