I want to create named HttpClients for each serve definition existing in the JSON file. But I have a problem with it. I do not know how to access this JSON file
JSON is defined like this in the project:
This file just contains a list of server names with their URLs:
{
"servers": [
{
"name": "first",
"url": "firstUrl"
},
{
"name": "second",
"url": "secondUrl"
}
]
}
Then in the main file I want to use it and created named HttpClients for each of the existing URL :
builder.Services.AddHttpClient("Name", client =>
{
client.BaseAddress = new Uri("Url");
client.Timeout = new TimeSpan(0, 0, 30);
});
so later I could create a specific HttpClients depending on the params received:
public async Task<Players> GetPlayers(string serverName)
{
var client = httpClientFactory.CreateClient(serverName);
var list = await client.GetAsAsync<Players>("players.xml");
return list;
}
