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 { PoolsApi, Configuration } from "cwmsjs";
const config = new Configuration({
headers: {
accept: 'application/json;version=2',
},
});
const p_api = new PoolsApi(config);
p_api
.getPoolsRaw({
office: 'SWT',
})
.then(async (r) => {
const data = r.raw.json();
return data;
})
.then((data) => {
console.log(data);
// data.forEach((category) => {
// console.log(category)
// console.log(category["id"])
// })
});
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 config = new cwmsjs.Configuration({
headers: {
accept: 'application/json;version=2',
},
});
const p_api = new cwmsjs.PoolsApi(config);
p_api
.getPoolsRaw({
office: 'SWT',
})
.then(async (r) => {
const data = r.raw.json();
return data;
})
.then((data) => {
console.log(data);
// data.forEach((category) => {
// console.log(category)
// console.log(category["id"])
// })
});
</script>
An example for calling the Pools endpoint via CDA in JavaScript
Swagger UI for Endpoints