Example: TurbineChange.js

An example for calling the TurbineChange.js endpoint via CDA in JavaScript

Swagger UI for Endpoints


Groundwork-Water + React

Checkout Groundwork-Water Hooks
The data components library for USACE made in React + Groundwork

Hooks are made wrapping CWMSjs using code similar to the React example below.
They also provide variables for you to track the state, progress, and data of the request.
The header on the Groundwork-Water webpage provides a list of currently available hooks.


React + Vite Example

To Install: npm install cwmsjs --save
import { TurbinesApi } from "cwmsjs";
import { Configuration } from "typedoc";

const tb_api = new TurbinesApi(config);
tb_api
    .getProjectsTurbines({
        projectId: 'KEYS',
        office: 'SWT',
    })
    .then((r) => r.raw.json())
    .then((data) => {
        console.log(data?.parameters);
        console.log(data?.parameters?.parameters);
        Object.entries(data?.parameters?.parameters).forEach(([key, value]) => {
            console.log(value?.['abstract-param']);
            console.log(value?.['office']);
            console.log(value?.['default-english-unit']);
            console.log(value?.['default-si-unit']);
            console.log(value?.['long-name']);
            console.log(value?.['description']);
        });
    })
    .catch(async (e) => {
        if (e.response) {
            const error_msg = e.response.json();
            e.message = `${e.response.url}\n${e.message}\n${JSON.stringify(error_msg, null, 2)}`;
            console.error(e);
            throw e;
        } else {
            throw e;
        }
    });



Bundle / Vanilla JS Example

To Install:

  1. Run
    curl -O "https://raw.githubusercontent.com/HydrologicEngineeringCenter/cwms-data-api-client-javascript/main/src/dist/bundle.js"
    to download bundle.js to your system
  2. Copy bundle.js to your web directory if not in that directory already
  3. <!-- Include the bundle.js file -->
    <script src="./bundle.js"></script>
    <!-- Call the cwmsjs after the bundle has loaded -->
    <script type="module">
    const tb_api = new cwmsjs.TurbinesApi(config);
    tb_api
        .getProjectsTurbines({
            projectId: 'KEYS',
            office: 'SWT',
        })
        .then((r) => r.raw.json())
        .then((data) => {
            console.log(data?.parameters);
            console.log(data?.parameters?.parameters);
            Object.entries(data?.parameters?.parameters).forEach(([key, value]) => {
                console.log(value?.['abstract-param']);
                console.log(value?.['office']);
                console.log(value?.['default-english-unit']);
                console.log(value?.['default-si-unit']);
                console.log(value?.['long-name']);
                console.log(value?.['description']);
            });
        })
        .catch(async (e) => {
            if (e.response) {
                const error_msg = e.response.json();
                e.message = `${e.response.url}\n${e.message}\n${JSON.stringify(error_msg, null, 2)}`;
                console.error(e);
                throw e;
            } else {
                throw e;
            }
        });
    
    </script>