Adding the request models

This commit is contained in:
2023-06-24 12:15:46 +02:00
parent e1a0fe68e8
commit 4419482152
4 changed files with 210 additions and 3 deletions

View File

@@ -1,7 +1,41 @@
const axios = require('axios')
class SpotifyController {
}
// Execute a GET request to the Spotify API
function executeGetRequest(url, requestObject, options, responseType){
return new Promise(function(resolve, reject){
axios.get(url, requestObject.serializeBinary(), options)
.then(function(response){
if (response.statusText !== 'OK') {
reject(`Request error (${response.status}): ${response.statusText}`)
} else {
resolve(responseType.deserializeBinary(response.data).toObject());
}
})
.catch(function(error){
reject(error)
})
})
}
// Execute a POST request to the Spotify API
function executePostRequest(url, requestObject, options, responseType){
return new Promise(function(resolve, reject){
axios.post(url, requestObject.serializeBinary(), options)
.then(function(response){
if (response.statusText !== 'OK') {
reject(`Request error (${response.status}): ${response.statusText}`)
} else {
resolve(responseType.deserializeBinary(response.data).toObject());
}
})
.catch(function(error){
reject(error)
})
})
}
module.exports = SpotifyController;