Second commit

added few test, first api to add book
This commit is contained in:
2025-09-23 17:16:48 +02:00
parent 0457ca2011
commit 8432902df1
19 changed files with 298 additions and 123 deletions

29
front/src/api.js Normal file
View File

@@ -0,0 +1,29 @@
import { ref } from 'vue'
const baseUrl = "http://localhost:8080"
function useFetch(url) {
const data = ref(null)
const error = ref(null)
fetch(url)
.then((res) => res.json())
.then((json) => (data.value = json))
.catch((err) => (error.value = err))
return { data, error }
}
export function getBooks() {
return useFetch(baseUrl + '/books');
}
export function postBook(book) {
fetch(baseUrl + '/book', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(book.value)
});
}