I have an api endpoint that returns these settings to a client HTML/JS that retrieve these data through either normal XML request or promise or async/await.
return new JsonResult(
new List<object>()
{
new { id = 1, size = "big", order = 6},
new { id = 2, size = "small", order = 4},
new { id = 3, size = "medium", order = 2},
new { id = 4, size = "small", order = 5},
new { id = 5, size = "small", order = 8, chips= new { }},
new { id = 6, size = "small", order = 7},
new { id = 7, size = "big", order = 1, chips= new { }},
new { id = 8, size = "small", order = 3},
new { id = 10, size = "big", order = 9},
new { id = 20, size = "big", order = 10}
});
however a new requirement come up that needs me to save these settings into a class and their value into a config file so we do not need to rebuild every time new settings are added.
This is the class I made:
public class Settings
{
public int Id { get;}
public string Size { get;}
public int Order { get;}
public int[] Arrays { get;}
}
I have been looking at creating configuration file and calling them. I just cannot wrap my head around how to save these value into a configuration file in an api so that it can be call in a client like this:
const getDataByPromise = function (method, url) {
return new Promise(function (resolve, reject) {
const xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function () {
if (successfulHttpResponse(this.status)) {
resolve(xhr.response);
document.getElementById("promise").textContent = xhr.responseText;
} else {
reject({
status: this.status,
statusText: xhr.statusText,
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText,
});
};
xhr.send();
});
};
How do you think I should go about implementing this