Skip to content

Commit 2a9ba2f

Browse files
authored
Merge pull request #13 from karthik2804/examples/split_examples
split example into smaller examples
2 parents be3e5b1 + d76761b commit 2a9ba2f

File tree

24 files changed

+175
-49
lines changed

24 files changed

+175
-49
lines changed

examples/KV/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__pycache__
2+
*.wasm
3+
.spin

examples/KV/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Spin python Key Value
2+
3+
A simple example showcasing the usage of Spin Key Value in the Spin Python SDK.

examples/KV/app.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from spin_http import Response
2+
from spin_key_value import kv_open_default
3+
4+
5+
def handle_request(request):
6+
7+
store = kv_open_default()
8+
9+
match request.method:
10+
case "GET":
11+
value = store.get(request.uri)
12+
return Response(200, [("content-type", "text/plain")], value)
13+
case "POST":
14+
store.set(request.uri, request.body)
15+
return Response(200, [("content-type", "text/plain")])
16+
case "DELETE":
17+
store.delete(request.uri)
18+
return Response(200, [("content-type", "text/plain")])
19+
case "HEAD":
20+
if store.exists(request.uri):
21+
return Response(200, [("content-type", "text/plain")])
22+
return Response(404, [("content-type", "text/plain")])
23+
case default:
24+
return Response(405, [("content-type", "text/plain")])

examples/KV/spin.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
spin_version = "1"
2+
authors = ["Fermyon Engineering <[email protected]>"]
3+
description = "Spin Python SDK KV"
4+
name = "spin-py-KV"
5+
trigger = { type = "http", base = "/" }
6+
version = "0.1.0"
7+
8+
[[component]]
9+
id = "python-sdk-example"
10+
source = "app.wasm"
11+
key_value_stores = ["default"]
12+
[component.trigger]
13+
route = "/..."
14+
[component.build]
15+
command = "spin py2wasm app -o app.wasm"

examples/external_lib/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__pycache__
2+
*.wasm
3+
.spin

examples/external_lib/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# External Libraries With Spin Python
2+
3+
A simple example showcasing the usage of an external library with the Spin Python SDK.

examples/external_lib/app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from spin_http import Response
2+
import toml
3+
4+
def handle_request(request):
5+
6+
some_toml = """
7+
title = "foo"
8+
[bar]
9+
baz = "wow"
10+
such = "toml"
11+
"""
12+
13+
return Response(200,
14+
[("content-type", "text/plain")],
15+
bytes(f"Toml content:{toml.loads(some_toml)}", "utf-8"))

examples/external_lib/spin.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
spin_version = "1"
2+
authors = ["Fermyon Engineering <[email protected]>"]
3+
description = "Spin Python SDK example using external library"
4+
name = "spin-py-external-library"
5+
trigger = { type = "http", base = "/" }
6+
version = "0.1.0"
7+
8+
[[component]]
9+
id = "python-sdk-example"
10+
source = "app.wasm"
11+
[component.trigger]
12+
route = "/..."
13+
[component.build]
14+
command = "spin py2wasm app -o app.wasm"

0 commit comments

Comments
 (0)