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);

}

...zur Antwort

const host = "http://localhost:3000";document.querySelector("#addMovie").addEventListener("click", createMovie)

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);}

easync 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);}

function generateID() { return (Date.now() + Math.random()).toString(36);}

async function movieExists(searchTitle) { const movieList = await getMovies(); // return movieList.filter(movie => movie.title === title); for (let i = 0; i < movieList.length; i++) { if (movieList[i].title === searchTitle) return true; } return false;}

const patchData = { ip: "12345"}

...zur Antwort

const host = "http://localhost:3000";document.querySelector("#addMovie").addEventListener("click", createMovie)

// GET-Anfrageasync function getMovies() { const res = await fetch(host + "/movieList"); const data = res.json(); return data;}

// POST-Anfrageasync function createMovie(e) {

e.preventDefault();

//erstelle ein neues Film-Objekt mit den Daten aus dem html-Formular: 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);}

// DELETE-Anfrageasync function deleteMovie(id) { const res = await fetch(host + "/movieList/" + id, { method: "DELETE" }); console.log(res);}

// PUT-Anfrageasync function putMovie(id) { const res = await fetch(host + "/movieList/" + id, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(correctedData) });}

// PATCH-Anfrage - ergänzt Einträgeasync function patchMovie(id) { const res = await fetch(host + "/movieList/" + id, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(patchData) }); console.log(res);}

// Hilfsfunktion zur Erzeugung einer neuen ID:function generateID() { return (Date.now() + Math.random()).toString(36);}

// Hilfsmethode zum Feststellen, ob ein Film mit gegebenem Titel existiert:async function movieExists(searchTitle) { const movieList = await getMovies(); // return movieList.filter(movie => movie.title === title); for (let i = 0; i < movieList.length; i++) { if (movieList[i].title === searchTitle) return true; } return false;}

const patchData = { ip: "12345"}

...zur Antwort

Die verkaufen Daten an andere Firmen

...zur Antwort