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 { TimeSeriesCategoriesApi } from "cwmsjs";
const OFFICE = 'SWT';
// Initialize the timeseries groups api with the default config
const tsc_api = new TimeSeriesCategoriesApi();
// Fetch ALL timeseries groups for the given office
tsc_api.getTimeSeriesCategory({ office: OFFICE }).then((data) => {
console.log(data[0]);
const CATEGORIES = data.map((cat) => cat.id);
data.forEach((category) => {
console.log(category.id);
});
console.log(`Fetched ${CATEGORIES.length} timeseries for office ${OFFICE}`);
});
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">
const OFFICE = 'SWT';
// Initialize the timeseries groups api with the default config
const tsc_api = new cwmsjs.TimeSeriesCategoriesApi();
// Fetch ALL timeseries groups for the given office
tsc_api.getTimeSeriesCategory({ office: OFFICE }).then((data) => {
console.log(data[0]);
const CATEGORIES = data.map((cat) => cat.id);
data.forEach((category) => {
console.log(category.id);
});
console.log(`Fetched ${CATEGORIES.length} timeseries for office ${OFFICE}`);
});
</script>
An example for calling the Timeseries Categories endpoint via CDA in JavaScript
Swagger UI for Endpoints