Second commit
added few test, first api to add book
This commit is contained in:
29
front/src/api.js
Normal file
29
front/src/api.js
Normal 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)
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user