Using Leafy Energy in enterprise environments with .NET
In many enterprise environments .NET/C# is the default. This demo section therefore includes a conceptual .NET client for Leafy Energy so architects immediately recognise the pattern.
Basic client class (concept)
public class LeafyClient
{
private readonly HttpClient _http;
public LeafyClient(string apiKey)
{
_http = new HttpClient
{
BaseAddress = new Uri("https://api.sandbox.leafy.energy")
};
_http.DefaultRequestHeaders.Add("Authorization", "Bearer " + apiKey);
}
public async Task<CurrentPrice> GetCurrentPriceAsync(string siteId)
{
var response = await _http.GetAsync($"/v1/pricing/current?site_id={siteId}");
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
return System.Text.Json.JsonSerializer.Deserialize<CurrentPrice>(json)!;
}
}
Examples like this make it easy to show .NET teams that Leafy Energy fits nicely into their existing stack.
Comments
0 comments
Please sign in to leave a comment.