File tree Expand file tree Collapse file tree 7 files changed +56
-3
lines changed
examples/http-tinygo-outbound-http
outbound-http-to-same-app Expand file tree Collapse file tree 7 files changed +56
-3
lines changed Original file line number Diff line number Diff line change 1+ module outbound-http-to-same-app
2+
3+ go 1.17
4+
5+ require github.com/fermyon/spin/sdk/go v0.0.0
6+
7+ require github.com/julienschmidt/httprouter v1.3.0 // indirect
8+
9+ replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../../sdk/go/
File renamed without changes.
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "net/http"
6+
7+ spinhttp "github.com/fermyon/spin/sdk/go/http"
8+ )
9+
10+ func init () {
11+ spinhttp .Handle (func (w http.ResponseWriter , r * http.Request ) {
12+ // Because we included self in `allowed_http_hosts`, we can make outbound
13+ // HTTP requests to our own app using a relative path.
14+ // This is not yet supported in cloud.
15+ resp , err := spinhttp .Get ("/hello" )
16+ if err != nil {
17+ http .Error (w , err .Error (), http .StatusInternalServerError )
18+ return
19+ }
20+
21+ fmt .Fprintln (w , resp .Body )
22+ fmt .Fprintln (w , resp .Header .Get ("content-type" ))
23+ })
24+ }
25+
26+ func main () {}
Original file line number Diff line number Diff line change @@ -7,9 +7,25 @@ version = "1.0.0"
77
88[[component ]]
99id = " tinygo-hello"
10- source = " main.wasm"
11- allowed_http_hosts = [" https://random-data-api.fermyon.app" , " https://postman-echo.com" ]
10+ source = " tinygo-hello/main.wasm"
11+ allowed_http_hosts = [
12+ " https://random-data-api.fermyon.app" ,
13+ " https://postman-echo.com" ,
14+ ]
1215[component .trigger ]
1316route = " /hello"
1417[component .build ]
18+ workdir = " tinygo-hello"
19+ command = " tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go"
20+
21+ [[component ]]
22+ id = " outbound-http-to-same-app"
23+ source = " outbound-http-to-same-app/main.wasm"
24+ # Use self to make outbound requests to components in the same Spin application.
25+ # `self` is not yet supported in cloud
26+ allowed_http_hosts = [" self" ]
27+ [component .trigger ]
28+ route = " /outbound-http-to-same-app"
29+ [component .build ]
30+ workdir = " outbound-http-to-same-app"
1531command = " tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go"
Original file line number Diff line number Diff line change @@ -6,4 +6,4 @@ require github.com/fermyon/spin/sdk/go v0.0.0
66
77require github.com/julienschmidt/httprouter v1.3.0 // indirect
88
9- replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../sdk/go/
9+ replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../../ sdk/go/
Original file line number Diff line number Diff line change 1+ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U =
2+ github.com/julienschmidt/httprouter v1.3.0 /go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM =
File renamed without changes.
You can’t perform that action at this time.
0 commit comments