I have a simple counter app that hits an API. When a user hits + button, it should make a PUT request to update the API. Question is, is it best practice to always pass a body in to update it. Or is it okay to just have an empty PUT request with logic?
/counter.js : empty body; just sending an PUT request:
const handleAdd = () => {
try {
const response = await fetch(`/api/counter`, {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
});
const counter = await response.json();
return counter;
} catch (err) {
return null;
}
};
return (
<button onClick={() => handleAdd()}> + </button>
)
/pages/api/counter.js
export default async function handler (req, res) {
add + 1
return res
}
Or should I have a generic update in counter.js and add body into the counter.js file?
export default async function handler (req, res) {
const newCounter = res
return res
}