Im pulling my hair tryna figure this out. How do you interact with the generated REST API?
Im trying to upsert a collection, But no specific examples:
export async function patchCartItems(userId, cartItems, onSuccess, onError) {
try {
const res = await fetch("/api/carts" + stringify({
where: {
user: {
equals: userId
}
}
}, { addQueryPrefix: true }),
{
method: "POST",
body: JSON.stringify(
{
user: userId,
items: cartItems
}
)
}
);
if (!res.ok) {
const error = new Error("Failed to fetch card");
error.info = await res.json();
error.status = res.status;
throw error;
}
const data = await res.json();
onSuccess && onSuccess(data);
return data;
} catch (error) {
console.log(error);
onError && onError(error);
return error;
}
}
How do you even do this?