const host = "http://localhost:3000";
document.querySelector("#addMovie").addEventListener("click", createMovie)
async function getMovies() {
const res = await fetch(host + "/movieList");
const data = res.json();
return data;
}
async function createMovie(e) {
e.preventDefault();
const movie = {
id: generateID(),
title: document.querySelector("#title").value,
year: document.querySelector("#year").value,
uploader: document.querySelector("#uploader").value,
ip: document.querySelector("#ip").value,
}
const res = await fetch(host + "/movieList", {
method: "POST",
headers: {
"Content-Type": 'application/json'
},
body: JSON.stringify(movie)
});
const data = await res.json();
console.log(data);
}
async function deleteMovie(id) {
const res = await fetch(host + "/movieList/" + id, {
method: "DELETE"
});
console.log(res);
}
async function putMovie(id) {
const res = await fetch(host + "/movieList/" + id, {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(correctedData)
});
}
async function patchMovie(id) {
const res = await fetch(host + "/movieList/" + id, {
method: "PATCH",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(patchData)
});
console.log(res);
}