Skip to content

Commit d44e19b

Browse files
authored
Merge pull request #1962 from vdice/chore/examples-v2-manifest
chore(examples): migrate to v2 manifest
2 parents 3950166 + 7e96856 commit d44e19b

File tree

41 files changed

+391
-395
lines changed

Some content is hidden

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

41 files changed

+391
-395
lines changed

examples/http-cpp/spin.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
spin_manifest_version = "1"
1+
spin_manifest_version = 2
2+
3+
[application]
24
authors = ["Fermyon Engineering <[email protected]>"]
35
description = "A simple application that returns hello."
46
name = "spin-hello-world"
5-
trigger = { type = "http" }
67
version = "1.0.0"
78

8-
[[component]]
9-
id = "hello"
9+
[[trigger.http]]
10+
route = "/hello"
11+
component = "hello"
12+
13+
[component.hello]
1014
source = "lib.wasm"
1115
description = "A simple component that returns hello."
12-
[component.trigger]
13-
route = "/hello"
14-
[component.build]
16+
[component.hello.build]
1517
command = "make"
Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,52 @@
1-
spin_manifest_version = "1"
1+
spin_manifest_version = 2
2+
3+
[application]
24
authors = ["Fermyon Engineering <[email protected]>"]
35
description = "Demonstrates outbound HTTP calls"
46
name = "spin-outbound-http"
5-
trigger = { type = "http" }
67
version = "1.0.0"
78

8-
[[component]]
9-
id = "outbound-http"
9+
[[trigger.http]]
10+
route = "/outbound"
11+
component = "outbound-http"
12+
13+
[[trigger.http]]
14+
route = "/wildcard"
15+
component = "outbound-http-wildcard"
16+
17+
[[trigger.http]]
18+
route = "/outbound-to-hello-component"
19+
component = "outbound-http-to-same-app"
20+
21+
[[trigger.http]]
22+
route = "/hello"
23+
component = "hello-component"
24+
25+
[component.outbound-http]
1026
source = "outbound-http/target/wasm32-wasi/release/http_rust_outbound_http.wasm"
1127
allowed_http_hosts = ["https://random-data-api.fermyon.app"]
12-
[component.trigger]
13-
route = "/outbound"
14-
[component.build]
28+
[component.outbound-http.build]
1529
workdir = "outbound-http"
1630
command = "cargo build --target wasm32-wasi --release"
1731

18-
[[component]]
19-
id = "outbound-http-wildcard"
32+
[component.outbound-http-wildcard]
2033
source = "outbound-http/target/wasm32-wasi/release/http_rust_outbound_http.wasm"
2134
allowed_http_hosts = ["insecure:allow-all"]
22-
[component.trigger]
23-
route = "/wildcard"
24-
[component.build]
35+
[component.outbound-http-wildcard.build]
2536
workdir = "outbound-http"
2637
command = "cargo build --target wasm32-wasi --release"
2738

28-
[[component]]
29-
id = "outbound-http-to-same-app"
39+
[component.outbound-http-to-same-app]
3040
source = "outbound-http-to-same-app/target/wasm32-wasi/release/outbound_http_to_same_app.wasm"
3141
# To make outbound calls to components in the same Spin app, use the special value self.
3242
allowed_http_hosts = ["self"]
33-
[component.trigger]
34-
route = "/outbound-to-hello-component"
35-
[component.build]
43+
[component.outbound-http-to-same-app.build]
3644
workdir = "outbound-http-to-same-app"
3745
command = "cargo build --target wasm32-wasi --release"
3846

39-
[[component]]
40-
id = "hello-component"
47+
[component.hello-component]
4148
source = "http-hello/target/wasm32-wasi/release/http_hello.wasm"
4249
description = "A simple component that returns hello."
43-
[component.trigger]
44-
route = "/hello"
45-
[component.build]
50+
[component.hello-component.build]
4651
workdir = "http-hello"
4752
command = "cargo build --target wasm32-wasi --release"
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
spin_manifest_version = "1"
1+
spin_manifest_version = 2
2+
3+
[application]
24
authors = ["Fermyon Engineering <[email protected]>"]
35
description = "An application that demonstrates HTTP routing."
46
name = "spin-rust-router"
5-
trigger = { type = "http" }
67
version = "1.0.0"
78

8-
[[component]]
9-
id = "route"
9+
[[trigger.http]]
10+
route = "/..."
11+
component = "route"
12+
13+
[component.route]
1014
source = "target/wasm32-wasi/release/http_rust_router_macro.wasm"
1115
description = "A component that internally routes HTTP requests."
12-
[component.trigger]
13-
route = "/..."
14-
[component.build]
16+
[component.route.build]
1517
command = "cargo build --target wasm32-wasi --release"
1618
watch = ["src/**/*.rs", "Cargo.toml", "spin.toml"]
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
spin_manifest_version = "1"
1+
spin_manifest_version = 2
2+
3+
[application]
24
authors = ["Fermyon Engineering <[email protected]>"]
35
description = "An application that demonstrates HTTP routing."
46
name = "spin-rust-router"
5-
trigger = { type = "http" }
67
version = "1.0.0"
78

8-
[[component]]
9-
id = "route"
9+
[[trigger.http]]
10+
route = "/..."
11+
component = "route"
12+
13+
[component.route]
1014
source = "target/wasm32-wasi/release/http_rust_router.wasm"
1115
description = "A component that internally routes HTTP requests."
12-
[component.trigger]
13-
route = "/..."
14-
[component.build]
16+
[component.route.build]
1517
command = "cargo build --target wasm32-wasi --release"
1618
watch = ["src/**/*.rs", "Cargo.toml", "spin.toml"]

examples/http-rust/spin.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
spin_manifest_version = "1"
1+
spin_manifest_version = 2
2+
3+
[application]
24
authors = ["Fermyon Engineering <[email protected]>"]
35
description = "A simple application that returns hello."
46
name = "spin-hello-world"
5-
trigger = { type = "http" }
67
version = "1.0.0"
78

8-
[[component]]
9-
id = "hello"
9+
[[trigger.http]]
10+
route = "/hello"
11+
component = "hello"
12+
13+
[component.hello]
1014
source = "target/wasm32-wasi/release/http_rust.wasm"
1115
description = "A simple component that returns hello."
12-
[component.trigger]
13-
route = "/hello"
14-
[component.build]
16+
[component.hello.build]
1517
command = "cargo build --target wasm32-wasi --release"
1618
watch = ["src/**/*.rs", "Cargo.toml"]

examples/http-tinygo-outbound-http/README.md

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,17 @@ components to send HTTP requests to certain hosts. This is configured in
1010
> [the Wasm examples](https://github.com/tinygo-org/tinygo/tree/release/src/examples/wasm).
1111
1212
Creating and sending HTTP requests from Spin components closely follows the Go
13-
`net/http` API:
14-
15-
```go
16-
r1, err := spin_http.Get("https://random-data-api.fermyon.app/animals/json")
17-
r2, err := spin_http.Post("https://postman-echo.com/post", "text/plain", bytes.NewBufferString("Hello there!"))
18-
19-
req, err := http.NewRequest("PUT", "https://postman-echo.com/put", bytes NewBufferString("General Kenobi!"))
20-
req.Header.Add("foo", "bar")
21-
r3, err := spin_http.Send(req)
22-
```
13+
`net/http` API. See [tinygo-hello/main.go](./tinygo-hello/main.go).
2314

2415
Building this as a WebAssembly module can be done using the `tinygo` compiler:
2516

2617
```shell
27-
$ go mod tidy
2818
$ spin build
29-
Executing the build command for component tinygo-hello: tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go
30-
Successfully ran the build command for the Spin components.
19+
Building component outbound-http-to-same-app with `tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go`
20+
Working directory: "./outbound-http-to-same-app"
21+
Building component tinygo-hello with `tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go`
22+
Working directory: "./tinygo-hello"
23+
Finished building all Spin components
3124
```
3225

3326
The component configuration must contain a list of all hosts allowed to send
@@ -37,15 +30,26 @@ HTTP requests to, otherwise sending the request results in an error:
3730
Cannot send HTTP request: Destination not allowed: <URL>
3831
```
3932

33+
The `tinygo-hello` component has the following allowed hosts set:
34+
35+
```toml
36+
[component.tinygo-hello]
37+
source = "tinygo-hello/main.wasm"
38+
allowed_http_hosts = [
39+
"https://random-data-api.fermyon.app",
40+
"https://postman-echo.com",
41+
]
42+
```
43+
44+
And the `outbound-http-to-same-app` uses the dedicated `self` keyword to enable making
45+
a request to another component in this same app, via a relative path (in this case, the component
46+
is `tinygo-hello` at `/hello`):
47+
4048
```toml
41-
[[component]]
42-
id = "tinygo-hello"
43-
source = "main.wasm"
44-
allowed_http_hosts = [ "https://random-data-api.fermyon.app", "https://postman-echo.com" ]
45-
[component.trigger]
46-
route = "/hello"
47-
[component.build]
48-
command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go"
49+
[component.outbound-http-to-same-app]
50+
source = "outbound-http-to-same-app/main.wasm"
51+
# Use self to make outbound requests to components in the same Spin application.
52+
allowed_http_hosts = ["self"]
4953
```
5054

5155
At this point, we can execute the application with the `spin` CLI:
@@ -58,11 +62,23 @@ The application can now receive requests on `http://localhost:3000/hello`:
5862

5963
```shell
6064
$ curl -i localhost:3000/hello -X POST -d "hello there"
65+
HTTP/1.1 200 OK
66+
content-length: 976
67+
date: Thu, 26 Oct 2023 18:26:17 GMT
68+
69+
{{"timestamp":1698344776965,"fact":"Reindeer grow new antlers every year"}}
70+
...
71+
```
6172

73+
As well as via the `/outbound-http-to-same-app` path to verify outbound http to the `tinygo-hello` component:
74+
75+
```shell
76+
$ curl -i localhost:3000/outbound-http-to-same-app
6277
HTTP/1.1 200 OK
63-
content-type: text/plain; charset=utf-8
64-
content-length: 789
65-
date: Wed, 09 Mar 2022 17:23:08 GMT
78+
content-length: 946
79+
date: Thu, 26 Oct 2023 18:26:53 GMT
80+
81+
{{{"timestamp":1698344813408,"fact":"Some hummingbirds weigh less than a penny"}}
6682
...
6783
```
6884

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1-
spin_manifest_version = "1"
1+
spin_manifest_version = 2
2+
3+
[application]
24
authors = ["Fermyon Engineering <[email protected]>"]
35
description = "A simple Spin application written in (Tiny)Go that performs outbound HTTP requests."
46
name = "spin-tinygo-outbound-http"
5-
trigger = { type = "http" }
67
version = "1.0.0"
78

8-
[[component]]
9-
id = "tinygo-hello"
9+
[[trigger.http]]
10+
route = "/hello"
11+
component = "tinygo-hello"
12+
13+
[[trigger.http]]
14+
route = "/outbound-http-to-same-app"
15+
component = "outbound-http-to-same-app"
16+
17+
[component.tinygo-hello]
1018
source = "tinygo-hello/main.wasm"
1119
allowed_http_hosts = [
1220
"https://random-data-api.fermyon.app",
1321
"https://postman-echo.com",
1422
]
15-
[component.trigger]
16-
route = "/hello"
17-
[component.build]
23+
[component.tinygo-hello.build]
1824
workdir = "tinygo-hello"
1925
command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go"
2026

21-
[[component]]
22-
id = "outbound-http-to-same-app"
27+
[component.outbound-http-to-same-app]
2328
source = "outbound-http-to-same-app/main.wasm"
2429
# Use self to make outbound requests to components in the same Spin application.
2530
allowed_http_hosts = ["self"]
26-
[component.trigger]
27-
route = "/outbound-http-to-same-app"
28-
[component.build]
31+
[component.outbound-http-to-same-app.build]
2932
workdir = "outbound-http-to-same-app"
3033
command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go"

0 commit comments

Comments
 (0)