Skip to content

Commit b443c72

Browse files
authored
Merge pull request #156 from vdice/templates/add-http-py-p2
feat(templates): add http-py-p2
2 parents bed3580 + 7f52237 commit b443c72

7 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__pycache__
2+
*.wasm
3+
.spin
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# A HTTP python component using componentize-py
2+
3+
This template uses the latest v3 version of the Spin Python SDK ([3.4.1](https://pypi.org/project/spin-sdk/3.4.1/))
4+
for compatibility with Spin 3.x (and hosts that use this major version). The 'p2' corresponds to the wasip2 or
5+
WASI Preview 2 set of WASI APIs, as used by Spin 3.x.
6+
7+
## Installing the requirements
8+
9+
To build the component, [`componentize-py`](https://pypi.org/project/componentize-py/) and [`spin-sdk`](https://pypi.org/project/spin-sdk/) are required. To install them, run:
10+
11+
```bash
12+
pip3 install -r requirements.txt
13+
```
14+
15+
## Building and Running
16+
17+
```
18+
spin up --build
19+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from spin_sdk.http import IncomingHandler, Request, Response
2+
3+
class IncomingHandler(IncomingHandler):
4+
def handle_request(self, request: Request) -> Response:
5+
return Response(
6+
200,
7+
{"content-type": "text/plain"},
8+
bytes("Hello from Python!", "utf-8")
9+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spin-sdk == 3.4.1
2+
componentize-py == 0.17.2
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
authors = ["{{authors}}"]
5+
description = "{{project-description}}"
6+
name = "{{project-name}}"
7+
version = "0.1.0"
8+
9+
[[trigger.http]]
10+
route = "{{http-path}}"
11+
component = "{{project-name | kebab_case}}"
12+
13+
[component.{{project-name | kebab_case}}]
14+
source = "app.wasm"
15+
[component.{{project-name | kebab_case}}.build]
16+
command = "componentize-py -w spin-http componentize app -o app.wasm"
17+
watch = ["*.py", "requirements.txt"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[[trigger.http]]
2+
route = "{{http-path}}"
3+
component = "{{project-name | kebab_case}}"
4+
5+
[component.{{project-name | kebab_case}}]
6+
source = "{{ output-path }}/app.wasm"
7+
[component.{{project-name | kebab_case}}.build]
8+
command = "componentize-py -w spin-http componentize app -o app.wasm"
9+
workdir = "{{ output-path }}"
10+
watch = ["*.py", "requirements.txt"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
manifest_version = "1"
2+
id = "http-py-p2"
3+
description = "HTTP request handler using Python compatible with Spin 3.x hosts"
4+
tags = ["http", "python", "py"]
5+
6+
[add_component]
7+
skip_files = ["spin.toml"]
8+
[add_component.snippets]
9+
component = "component.txt"
10+
11+
[parameters]
12+
project-description = { type = "string", prompt = "Description", default = "" }
13+
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }

0 commit comments

Comments
 (0)