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 { CatalogApi } from "cwmsjs";
const catalog_api = new CatalogApi();
catalog_api
.getCatalogWithDataset({
office: 'SWT',
like: 'KEYS..*.Inst.1Hour.0.Ccp-Rev',
dataset: 'TIMESERIES',
})
.then((data) => {
console.log(data?.entries);
Object.entries(data?.entries).forEach(([key, value]) => {
console.log(value?.name);
});
console.log(`Returned ${data?.entries?.length} timeseries IDs`);
});
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 catalog_api = new cwmsjs.CatalogApi();
catalog_api
.getCatalogWithDataset({
office: 'SWT',
like: 'KEYS..*.Inst.1Hour.0.Ccp-Rev',
dataset: 'TIMESERIES',
})
.then((data) => {
console.log(data?.entries);
Object.entries(data?.entries).forEach(([key, value]) => {
console.log(value?.name);
});
console.log(`Returned ${data?.entries?.length} timeseries IDs`);
});
</script>
An example for calling the Catalog endpoint via CDA in JavaScript
Swagger UI for Endpoints