71 lines
1.5 KiB
JavaScript
71 lines
1.5 KiB
JavaScript
const uri = "http://localhost:8081";
|
|
|
|
export async function getMovies() {
|
|
const response = await fetch(`${uri}/movies`);
|
|
if (!response.ok) {
|
|
throw response.statusText;
|
|
}
|
|
|
|
return response.json();
|
|
}
|
|
|
|
export async function getMovieById(id) {
|
|
const response = await fetch(`${uri}/movies/${id}`);
|
|
if (!response.ok) {
|
|
throw response.statusText;
|
|
}
|
|
|
|
return response.json();
|
|
}
|
|
|
|
export async function createMovie(serializedMovie) {
|
|
console.log(serializedMovie);
|
|
|
|
const options = {
|
|
method: 'POST',
|
|
body: JSON.stringify(serializedMovie),
|
|
headers: {
|
|
"Accept": "application/json",
|
|
"Content-Type": "application/json",
|
|
},
|
|
};
|
|
|
|
const response = await fetch(`${uri}/movies`, options);
|
|
if (!response.ok) {
|
|
throw response.statusText;
|
|
}
|
|
|
|
return response.json();
|
|
}
|
|
|
|
export async function updateMovie(id, serializedMovie) {
|
|
const options = {
|
|
method: "PUT",
|
|
body: JSON.stringify(serializedMovie),
|
|
headers: {
|
|
"Accept": "application/json",
|
|
"Content-Type": "application/json",
|
|
},
|
|
};
|
|
|
|
const response = await fetch(`${uri}/movies/${id}`, options);
|
|
if (!response.ok) {
|
|
throw response.statusText;
|
|
}
|
|
|
|
return response.json();
|
|
}
|
|
|
|
export async function deleteMovie(id) {
|
|
const options = {
|
|
method: "DELETE",
|
|
};
|
|
|
|
const response = await fetch(`${uri}/movies/${id}`, options);
|
|
if (!response.ok) {
|
|
throw response.statusText;
|
|
}
|
|
|
|
return response.json();
|
|
}
|