using System.Collections.Generic;
using System.Net.Http.Json;
HttpClient client = new()
BaseAddress = new Uri("https://fireboard.io")
using StringContent json = new(JsonSerializer.Serialize(new { username = "sidneylandrews@gmail.com", password = "n5BD8J3w^yHA" }), Encoding.UTF8, "application/json");
using HttpResponseMessage loginResponse = await client.PostAsync("api/rest-auth/login/", json);
loginResponse.EnsureSuccessStatusCode().WriteRequestToConsole();
var loginResource = await loginResponse.Content.ReadFromJsonAsync<Login>();
Console.WriteLine($"{loginResource}");
using HttpResponseMessage devicesResponse = await client.GetAsync("/api/v1/devices.json");
devicesResponse.EnsureSuccessStatusCode().WriteRequestToConsole();
var devicesJson = await devicesResponse.Content.ReadAsStringAsync();
Console.WriteLine($"{devicesJson}");
var devicesResources = devicesResponse.Content.ReadFromJsonAsAsyncEnumerable<Device>();
await foreach(var deviceResource in devicesResources)
Console.WriteLine($"{deviceResource}");
internal record Login(string key);
internal record Device(int id, string uuid, string title, DateTime created, string hardware_id);
internal static class ExtensionMethods
internal static void WriteRequestToConsole(this HttpResponseMessage response)
var request = response.RequestMessage;
Console.Write($"{request?.Method} ");
Console.Write($"{request?.RequestUri} ");
Console.WriteLine($"HTTP/{request?.Version}");