To fetch the updated and totalBunnies values separately, you would need to modify your server-side code to provide separate endpoints for each value. However, based on the provided information, your current GET API route returns both totalBunniesValue and updatedValue together.
Assuming you have separate endpoints set up on the server-side, here's how you can structure the fetch requests:
- To fetch the
updated value:
async function fetchUpdatedValue() {
try {
const response = await fetch('/api/bunnies/updated', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error('Network response not ok');
}
const data = await response.json();
console.log('Retrieved updated value:', data.updated);
}
catch (error) {
console.error('Error: ', error);
}
}
- To fetch the
totalBunnies value:
async function fetchTotalBunniesValue() {
try {
const response = await fetch('/api/bunnies/totalBunnies', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error('Network response not ok');
}
const data = await response.json();
console.log('Retrieved total bunnies value:', data.totalBunnies);
}
catch (error) {
console.error('Error: ', error);
}
}
In these functions, /api/bunnies/updated and /api/bunnies/totalBunnies are the endpoints that return the updated and totalBunnies values, respectively. The updated and totalBunnies values are then logged to the console.