Skip to content

Instantly share code, notes, and snippets.

@jatinkumar725
Last active November 26, 2024 20:57
Show Gist options
  • Save jatinkumar725/e0537653245c9424140765df64e11445 to your computer and use it in GitHub Desktop.
Save jatinkumar725/e0537653245c9424140765df64e11445 to your computer and use it in GitHub Desktop.
Post request in Fetch method
// Handling Adding the new User to the Server
const handleAddUser = async () => {
try {
const response = await fetch(
"https://user-dummy-api.onrender.com/users",
{
method: "POST",
body: JSON.stringify(userDetails.addModal),
headers: {
"Content-Type": "application/json"
}
}
);
if (response.status === 201) {
handleDisplayModal("addModal");
Swal.fire({
title: "User Added Successfully",
icon: "success"
});
setLoading(true);
gettingUsers();
setUserDetails(initialValues);
}
} catch (error) {
console.log(error);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment