Skip to content

Example web app using the solarnetwork-datum-loader package to query SolarNetwork for large data sets, using TypeScript.

Notifications You must be signed in to change notification settings

SolarNetwork/solarnetwork-example-ts-datum-loader

Repository files navigation

SolarNetwork Example: TypeScript Datum Loader

This project is a little web app to show the basics of using the SolarNetwork API in a TypeScript project to download large sets of datum stream data using the DatumLoader helper class.

You can see the example in action here:

https://go.solarnetwork.net/dev/example/typescript-datum-loader/

Screenshot of the TypeScript Datum Loader app

Key aspects

There are a few key aspects of this example worth pointing out.

SolarNetwork API

The solarnetwork-datum-loader package is included in the project, which provides many helpful utilities in both TypeScript and JavaScript for working with the SolarNetwork API.

{
	"dependencies": {
		"solarnetwork-datum-loader": "^2.0.0"
	}
}

Token authentication with Fetch API

The example demonstrates using SolarNetwork token authentication with the browser Fetch API.

First the demo imports the AuthorizationV2Builder class and creates a reusable instance in an auth variable:

import { AuthorizationV2Builder } from "solarnetwork-api-core/lib/net";

const auth = new AuthorizationV2Builder();

A change form event handler listens for changes to the form's token and secret fields, and saves the credentials for future API calls:

// save credentials
auth.tokenId = settingsForm.snToken.value;
auth.saveSigningKey(settingsForm.snTokenSecret.value);

Building from source

To build yourself, clone or download this repository. You need to have Node 16+ installed. Then:

# initialize dependencies
npm ci

# run development live server on http://localhost:8080
npm run dev

# build for production
npm run build

Running the build script will generate the application into the dist/ directory.

About

Example web app using the solarnetwork-datum-loader package to query SolarNetwork for large data sets, using TypeScript.

Topics

Resources

Stars

Watchers

Forks