Skip to content

Commit a2a679b

Browse files
committed
add geolocation weather example
+ requires api token for weather site + can provide an ip addr to test with SPIN_VARIABLE_TEST_IP_ADDR=<some ip> SPIN_VARIABLE_WAQI_API_TOKEN=<some token> spin up Signed-off-by: Michelle Dhanani <[email protected]>
1 parent 93ec341 commit a2a679b

11 files changed

+4027
-0
lines changed
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
dist
3+
target
4+
.spin/
5+
build/
6+
.spin-aka/

samples/geolocation-weather/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KNITWIT_SOURCE=./config/knitwit.json

samples/geolocation-weather/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Geolocation Weather Application
2+
3+
This sample illustrates how to fetch weather data from an API based on the user's geolocation data. Behind the scenes, ip-api.com is used to look up the latitude, longitude coordinates using the client's IP address and aqicn.org is used to fetch weather data.
4+
5+
Caution: When running locally, this sample will use a default IP address instead of 127.0.0.1 for the client IP address which can be overriden for test purposes on the CLI.
6+
7+
## Prerequisites
8+
9+
- Spin CLI
10+
- Spin `aka` plugin
11+
- WAQI API token from [https://aqicn.org/api/](https://aqicn.org/api/)
12+
13+
## Deploy to FWF
14+
15+
Once you've cloned the repository and moved to the ./samples/geolocation-weather, install the dependencies, build and run the app:
16+
17+
```console
18+
spin build
19+
spin aka deploy --variable waqi_api_token=<your_api_token_here>
20+
```
21+
22+
The `spin aka deploy` command will print the application URL to `stdout`.
23+
24+
Use the browser to see application running at the address printed.
25+
26+
## Running locally
27+
28+
```console
29+
spin build
30+
SPIN_VARIABLE_WAQI_API_TOKEN=<your_api_token_here> spin up
31+
```
32+
33+
To test with a specific client ip address:
34+
35+
```console
36+
SPIN_VARIABLE_TEST_IP_ADDR=<client_ip_here> \
37+
SPIN_VARIABLE_WAQI_API_TOKEN=<your_api_token_here> spin up
38+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": 1,
3+
"project": {
4+
"worlds": [
5+
"spin-http"
6+
]
7+
},
8+
"packages": {
9+
"@fermyon/spin-sdk": {
10+
"witPath": "../../bin/wit",
11+
"world": "spin-imports"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)