temperature-alarm/frontend/services/users.service.js
2025-03-18 10:53:17 +01:00

40 lines
1.3 KiB
JavaScript

const address = "http://10.135.51.116/temperature-alarm-webapi/users"
function login(username, password) {
fetch(`${address}/login`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({username: username, password: password})
})
.then(response => response.json())
.then(data => console.log("Success:", data))
.catch(error => console.error("Error:", error));
}
function create(email, username, password){
fetch(`${address}/create`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({email: email, username: username, password: password})
})
.then(response => response.json())
.then(data => console.log("Success:", data))
.catch(error => console.error("Error:", error));
}
function update(email, username, password){
fetch(`${address}/update`, {
method: "PATCH",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({email: email, username: username, password: password})
})
.then(response => response.json())
.then(data => console.log("Success:", data))
.catch(error => console.error("Error:", error));
}