I'd like to build a dropdown using the results of a local http request. I'll be hitting an ExpressJS server that's using serve-index to provide a directory listing of files. Unfortunately, unless I add Accept: application/json to the GET request, what's returned is formatted as html and not as the JSON array I require.
Has there been any interest in expanding httpGet() so that headers could be added? Are there use cases where JSON is not the desired format?
I'm looking into the Custom Module approach, @jean-emmanuel, which seems to avoid the header issue. I only need to get my file list once, when the server starts, so I assume I'd put the GET in init. I only want to pass along the array of filenames, like this–
const axios = nativeRequire('axios');
module.exports = {
init: function() {
// this will be executed once when the osc server starts
axios.get('http://localhost:8889/transits')
.then(function (response) {
return(response.data);
})
.catch(function (error) {
console.log(error);
})
},
}
–but I do not know how to wire this up so that the values for my dropdown are replaced by the array of filenames.
init is called only when the server starts, which usually happens before any client is connected. This would work better:
app.on('sessionOpened', (data, client)=>{
// fetch/process data
//...
// send data to an osc receiver (OSC{} syntax) in the appropriate property
receive('/osc_receiver_address', data, {clientId: clients.id})
})