19 lines
678 B
JavaScript
19 lines
678 B
JavaScript
|
function execQuery(table, filter = "all", id = -1){
|
||
|
let baseHttpRequest = "https://dwarves.iut-fbleau.fr/~fauvet/api/"
|
||
|
let computeHttpRequest;
|
||
|
if(filter !== undefined){
|
||
|
switch(table){
|
||
|
case "songs":
|
||
|
computeHttpRequest = baseHttpRequest+table+"?title="+filter;
|
||
|
default :
|
||
|
computeHttpRequest = baseHttpRequest+table+"?name="+filter;
|
||
|
}
|
||
|
} else if(id !== undefined) {
|
||
|
computeHttpRequest = baseHttpRequest+table+"/"+id;
|
||
|
} else {
|
||
|
computeHttpRequest = baseHttpRequest+table;
|
||
|
}
|
||
|
return fetch(computeHttpRequest).then(response => {
|
||
|
return response.json();
|
||
|
});
|
||
|
};
|