NPM Client Example
This folder contains an example for WebAPI client in NPM. Client library would be pulled from GitHub Packages.
TypeDoc is here.
Requirements
- WebAPI instance
- See the Overview if you'd like to start it on container.
- Node.js 18 or later
Client code
index.js is an example program to call WebAPI endpoint. It calls all of endpoints, and shows the result.
Following methods are available:
processBestEmissionsDataByLocations
- Call /emissions/bylocations/best
- Gather the best emission data for west/central/east US yesterday.
processEmissionsDataByLocations
- Call /emissions/bylocations
- Gather emission data for west/central/east US yesterday.
processEmissionsDataByLocation
- Call /emissions/bylocation
- Gather emission data for westus yesterday.
processCurrentForecastData
- Call /emissions/forecasts/current
- Gather forecast data for westus.
processForecastBatchData
- Call /emissions/forecasts/batch
- Gather forecast data for westus.
processAverageData
- Call /emissions/average-carbon-intensity .
- Gather average data for westus yesterday.
processAverageBatchData
- Call /emissions/average-carbon-intensity/batch
- Gather average data for westus yesterday.
How it works
1. Set WebAPI endpoint
You need to set base URL of WebAPI endpoint in index.ts
. http://localhost:8080
is set by default.
const conf = new Configuration({basePath: 'http://localhost:8080'});
2. Install required packages
You have to run npm install
at first. CASDK client module would be downloaded from GitHub Packages, so you need to set GitHub Parsonal Access Token. You can set it to GH_TOKEN
environment variable used in .npmrc.
If you have not yet got GitHub PAT, see this guide.
GH_TOKEN=<GitHub PAT> npm install
3. Run
npx ts-node index.ts