Skip to content

Commit 3463927

Browse files
feat(examples): make get-weather-js work without an API key (microsoft#294)
1 parent 9781198 commit 3463927

File tree

9 files changed

+1631
-0
lines changed

9 files changed

+1631
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
*.wasm
4+
pnpm-lock.yaml
5+
out-dir
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build:
2+
npm install
3+
npm run build:component
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Get Weather Example (JavaScript)
2+
3+
This example demonstrates how to get the weather for a given location using a Wassette component written in JavaScript.
4+
5+
For more information on installing Wassette, please see the [installation instructions](https://github.com/microsoft/wassette?tab=readme-ov-file#installation).
6+
7+
## Usage
8+
9+
This component uses the [Open-Meteo API](https://open-meteo.com/), which provides free weather data without requiring authentication.
10+
11+
Load the component from the OCI registry and provide a city name.
12+
13+
**Load the component:**
14+
15+
```
16+
Please load the component from oci://ghcr.io/microsoft/get-weather-js:latest
17+
```
18+
19+
**Get the weather:**
20+
21+
```
22+
get the weather for Toronto
23+
```
24+
25+
## Policy
26+
27+
By default, WebAssembly (Wasm) components do not have any access to the host machine or network. The `policy.yaml` file is used to explicitly define what network resources and environment variables are made available to the component. This ensures that the component can only access the resources that are explicitly allowed.
28+
29+
Example:
30+
31+
```yaml
32+
version: "1.0"
33+
description: "Permission policy for wassette weather demo"
34+
permissions:
35+
network:
36+
allow:
37+
- host: "geocoding-api.open-meteo.com" # For geocoding city names to coordinates
38+
- host: "api.open-meteo.com" # For fetching weather data
39+
```
40+
41+
The source code for this example can be found in [`weather.js`](weather.js).
75.1 KB
Loading

0 commit comments

Comments
 (0)