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.
npm install cwmsjs --save
import { TimeSeriesApi, Configuration } from "cwmsjs";
// ⚠️ NOTE!
// Do NOT use V1 of the Timeseries endpoint.
// It is deprecated and will be removed in the future❗
// This serves as an example of how to use the V1 API for legacy purposes.
const ts_api = new TimeSeriesApi();
ts_api
.getTimeSeries({
office: 'SWT',
name: 'KEYS.Elev.Inst.1Hour.0.Ccp-Rev',
})
.then((data) => {
console.log(data);
});
curl -O "https://raw.githubusercontent.com/HydrologicEngineeringCenter/cwms-data-api-client-javascript/main/src/dist/bundle.js"
<!-- Include the bundle.js file -->
<script src="./bundle.js"></script>
<!-- Call the cwmsjs after the bundle has loaded -->
<script type="module">
// ⚠️ NOTE!
// Do NOT use V1 of the Timeseries endpoint.
// It is deprecated and will be removed in the future❗
// This serves as an example of how to use the V1 API for legacy purposes.
const ts_api = new cwmsjs.TimeSeriesApi();
ts_api
.getTimeSeries({
office: 'SWT',
name: 'KEYS.Elev.Inst.1Hour.0.Ccp-Rev',
})
.then((data) => {
console.log(data);
});
</script>
An example for calling the TimeSeries - Version 1 endpoint via CDA in JavaScript
Swagger UI for Endpoints