Example: Ratings

An example for calling the Ratings 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 { RatingsApi, Configuration } from "cwmsjs";


const config_v2 = new Configuration({
    headers: {
        accept: 'application/json;version=2',
    },
});
const r_api = new RatingsApi(config_v2);
r_api
    .getRatings({
        office: 'SWT',
    })
    .then((data) => {
        console.log(data);
    });
//   Fetch the CWMS Rating specification for the SWT OFFICE given a rating mask for keystone lake
r_api
    .getRatingsSpec({
        office: 'SWT',
        ratingIdMask: 'KEYS.*',
    })
    .then((data) => {
        console.log(data?.specs);
    });
//   Fetch the CWMS Rating templates for the SPK OFFICE
r_api
    .getRatingsTemplate({
        office: 'SPK',
    })
    .then((data) => {
        console.log(data?.templates);
    });

//   r_api
//     .getRatingsTemplateWithTemplateId({
//       office: "SWT",
//       templateId: "Elev-Alt;Stor-Alt.Linear",
//     })
//     .then((data) => {
//       console.log(data);
//     });



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 config_v2 = new cwmsjs.Configuration({
        headers: {
            accept: 'application/json;version=2',
        },
    });
    const r_api = new cwmsjs.RatingsApi(config_v2);
    r_api
        .getRatings({
            office: 'SWT',
        })
        .then((data) => {
            console.log(data);
        });
    //   Fetch the CWMS Rating specification for the SWT OFFICE given a rating mask for keystone lake
    r_api
        .getRatingsSpec({
            office: 'SWT',
            ratingIdMask: 'KEYS.*',
        })
        .then((data) => {
            console.log(data?.specs);
        });
    //   Fetch the CWMS Rating templates for the SPK OFFICE
    r_api
        .getRatingsTemplate({
            office: 'SPK',
        })
        .then((data) => {
            console.log(data?.templates);
        });
    
    //   r_api
    //     .getRatingsTemplateWithTemplateId({
    //       office: "SWT",
    //       templateId: "Elev-Alt;Stor-Alt.Linear",
    //     })
    //     .then((data) => {
    //       console.log(data);
    //     });
    
    </script>