using System.Text; using System.Text.Json.Nodes; namespace FsTool.Helpers { public static class Extensions { #region Public Method FsPostAsync /// /// Sends a POST request to the specified URI with the provided JSON content. /// /// The instance of used to send the request. /// The URI to which the request is sent. /// The JSON object to include in the request body. /// A task that represents the asynchronous operation. The task result contains the HTTP response. public static async Task FsPostAsync(this HttpClient httpClient, string requestUri, JsonObject jsonObject) { var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json"); content.Headers.ContentType = new("application/json"); return await httpClient.PostAsync(requestUri, content); } #endregion #region Public Method ToList /// /// Converts the specified JSON node into a list of non-null elements. /// /// The to be converted. If null, an empty list is returned. /// A list of instances containing non-null elements. public static List ToList(this JsonNode? node) { var array = node?.AsArray() ?? []; return array.Where(x => x != null).Select(x => x!).ToList(); } #endregion } }