Skip to content

Commit 7a2eb66

Browse files
committed
chore(examples): migrate to Spin manifest v2 + README/misc updates
Signed-off-by: Vaughn Dice <vaughn.dice@fermyon.com>
1 parent 797569b commit 7a2eb66

File tree

40 files changed

+240
-165
lines changed

40 files changed

+240
-165
lines changed

examples/javascript/hello_world/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ This is the simplest example of using the Javascript SDK.
55
### Building the example
66

77
```console
8+
npm install
89
spin build
910
```
1011

1112
### Running the example
1213

1314
```console
14-
spin up --follow-all
15+
spin up
1516
```
1617

1718
Use e.g. `curl -v http://127.0.0.1:3000/hello` to test the endpoint.
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
spin_manifest_version = "1"
1+
spin_manifest_version = 2
2+
3+
[application]
24
authors = ["Fermyon Engineering <engineering@fermyon.com>"]
35
name = "spin-http-js"
4-
trigger = { type = "http", base = "/" }
56
version = "1.0.0"
67

7-
[[component]]
8-
id = "hello"
9-
source = "target/spin-http-js.wasm"
10-
[component.trigger]
8+
[[trigger.http]]
119
route = "/hello"
12-
[component.build]
10+
component = "hello"
11+
12+
[component.hello]
13+
source = "target/spin-http-js.wasm"
14+
[component.hello.build]
1315
command = "npm install && npm run build"

examples/javascript/http-router/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ The app exposes the following endpoints:
1212

1313
## Build and run the app locally
1414

15+
First, install npm dependencies with `npm install`.
16+
1517
To build and run the app locally, you can either use `spin build` and `spin up` or combine both commands and simply run `spin build --up`.
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 = ["Thorsten Hans <thorsten.hans@gmail.com>"]
35
description = "Sample to demonstrate the usage of the HTTP router"
46
name = "http-router"
5-
trigger = { type = "http", base = "/" }
67
version = "0.1.0"
78

8-
[[component]]
9-
id = "http-router"
9+
[[trigger.http]]
10+
route = "/..."
11+
component = "http-router"
12+
13+
[component.http-router]
1014
source = "target/http-router.wasm"
1115
exclude_files = ["**/node_modules"]
12-
[component.trigger]
13-
route = "/..."
14-
[component.build]
16+
[component.http-router.build]
1517
command = "npm run build"

examples/javascript/kv/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ The app leverages the `default` key-value store as specified in `spin.toml`.
1515

1616
## Build and run the app locally
1717

18+
First, install npm dependencies with `npm install`.
19+
1820
To build and run the app locally, you can either use `spin build` and `spin up` or combine both commands and simply run `spin build --up`.

examples/javascript/kv/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 = ["Thorsten Hans <thorsten.hans@gmail.com>"]
35
description = "Demonstrates how to use key-value store APIs in JS"
46
name = "kv"
5-
trigger = { type = "http", base = "/" }
67
version = "0.1.0"
78

8-
[[component]]
9-
id = "kv"
9+
[[trigger.http]]
10+
route = "/..."
11+
component = "kv"
12+
13+
[component.kv]
1014
source = "target/kv.wasm"
1115
key_value_stores = ["default"]
1216
exclude_files = ["**/node_modules"]
13-
[component.trigger]
14-
route = "/..."
15-
[component.build]
17+
[component.kv.build]
1618
command = "npm run build"

examples/javascript/outbound-http/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ This example showcases utilizing fetch to request data from an API and use it in
55
### Building the example
66

77
```
8-
npm run build
8+
npm install
9+
spin build
910
```
11+
1012
### Running the example
1113

1214
```
13-
spin up --follow-all
15+
spin up
1416
```
1517

1618
Use e.g. `curl -v http://127.0.0.1:3000/hello` to test the endpoint.

examples/javascript/outbound-http/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build": "npx webpack --mode=production && mkdir -p target && spin js2wasm -o target/spin-http-js.wasm dist/spin.js",
7+
"build": "npx webpack --mode=production && mkdir -p target && spin js2wasm -o target/spin-outbound-http.wasm dist/spin.js",
88
"test": "echo \"Error: no test specified\" && exit 1"
99
},
1010
"keywords": [],
Lines changed: 12 additions & 10 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 <engineering@fermyon.com>"]
3-
name = "spin-http-js"
4-
trigger = { type = "http", base = "/" }
5+
name = "spin-outbound-http"
56
version = "1.0.0"
67

7-
[[component]]
8-
id = "hello"
9-
source = "target/spin-http-js.wasm"
10-
allowed_http_hosts = ["https://some-random-api.ml"]
11-
files = ["src/index.html"]
12-
[component.trigger]
8+
[[trigger.http]]
139
route = "/hello"
14-
[component.build]
10+
component = "hello"
11+
12+
[component.hello]
13+
source = "target/spin-outbound-http.wasm"
14+
allowed_http_hosts = ["random-data-api.fermyon.app"]
15+
files = ["src/index.js"]
16+
[component.hello.build]
1517
command = "npm run build"

examples/javascript/outbound-http/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const encoder = new TextEncoder("utf-8")
22
const decoder = new TextDecoder("utf-8")
33

44
export async function handleRequest(request) {
5-
const dogFact = await fetch("https://some-random-api.ml/facts/dog")
5+
const physicsFact = await fetch("https://random-data-api.fermyon.app/physics/json")
66

7-
const dogFactBody = decoder.decode(await dogFact.arrayBuffer() || new Uint8Array())
7+
const physicsFactBody = decoder.decode(await physicsFact.arrayBuffer() || new Uint8Array())
88

99
const env = JSON.stringify(process.env)
1010

11-
const body = `Here's a dog fact: ${dogFactBody}\n`
11+
const body = `Here's a physics fact: ${physicsFactBody}\n`
1212

1313
return {
1414
status: 200,

0 commit comments

Comments
 (0)