Skip to content

Commit f6635eb

Browse files
committed
refactor(frontend): simplify fetch call formatting and standardize form POST
1 parent 5131e28 commit f6635eb

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

chat-app/frontend/script.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@ async function getAllMessages() {
4343
likeButton.textContent = "Like";
4444

4545
likeButton.addEventListener("click", async () => {
46-
await fetch(
47-
`${API_BASE_URL}/messages/${message.id}/like`,
48-
{
49-
method: "POST",
50-
},
51-
);
46+
await fetch(`${API_BASE_URL}/messages/${message.id}/like`, {
47+
method: "POST",
48+
});
5249
});
5350

5451
// put it all together
@@ -89,19 +86,16 @@ formElement.addEventListener("submit", async (event) => {
8986

9087
try {
9188
// Send the data
92-
const response = await fetch(
93-
`${API_BASE_URL}/messages`,
94-
{
95-
method: "POST",
96-
headers: {
97-
"Content-Type": "application/json",
98-
},
99-
body: JSON.stringify({
100-
sender: senderValue,
101-
text: messageValue,
102-
}),
89+
const response = await fetch(`${API_BASE_URL}/messages`, {
90+
method: "POST",
91+
headers: {
92+
"Content-Type": "application/json",
10393
},
104-
);
94+
body: JSON.stringify({
95+
sender: senderValue,
96+
text: messageValue,
97+
}),
98+
});
10599

106100
if (response.ok) {
107101
// clear the sender and message input values

0 commit comments

Comments
 (0)