Skip to content
Snippets Groups Projects
Commit 217b3128 authored by fz2907's avatar fz2907
Browse files

Added ServerHttpService.js, Constants.js, ExampleService.js, and changed...

Added ServerHttpService.js, Constants.js, ExampleService.js, and changed HelloWorld.vue for show examples.
The front to back end connection is ready.
parent 5e0bc556
No related branches found
No related tags found
3 merge requests!27Sprint 1 done,!7Changed DB port from 3306 to 3307. So it will not interrupt with your own local MySQL,!5Added ServerHttpService.js, Constants.js, ExampleService.js, and changed HelloWorld.vue for show examples. The front to back end connection is ready.
/**
* This class will handle the http request that send to server.
* It will help debuging and handle cookie if needed.
*/
import Constants from "@/services/Constants";
export default{
Get(path){
let url = Constants.Server_URL + path;
console.log("GET from: " + url);
return fetch(url,{
method: "GET"
})
.then((response) =>{
if(response.ok){
return response.json();
}
throw new Error("Unable to receive GET request from server with url:" + url);
})
.catch((reason) =>{
console.log("Error on GET request", reason);
});
},
Post(path, bodyData){
let url = Constants.Server_URL + path;
console.log("POST from: " + url);
return fetch(url,{
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(bodyData)
})
.then((response)=>{
if(response.ok){
return response.json();
}
throw new Error("Unable to receive POST request from server with url:" + url);
})
.catch((reason) =>{
console.log("Error on POST request", reason);
});
},
Put(path, bodyData){
let url = Constants.Server_URL + path;
console.log("PUT from: " + url);
return fetch(url,{
method: "PUT",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(bodyData)
})
.then((response)=>{
if(response.ok){
return response.json();
}
throw new Error("Unable to receive PUT request from server with url:" + url);
})
.catch((reason) =>{
console.log("Error on PUT request", reason);
});
},
Delete(path){
let url = Constants.Server_URL + path;
console.log("Delete from: " + url);
return fetch(url,{
method: "Delete",
})
.then((response)=>{
if(response.ok){
return response.json();
}
throw new Error("Unable to receive DELETE request from server with url:" + url);
})
.catch((reason) =>{
console.log("Error on DELETE request", reason);
});
},
}
/*
Change logs:
Date | Author | Description
2022-10-12 | Fangzheng Zhang | create class and init
*/
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment