Skip to content

Commit

Permalink
Allow option for ApiRequest to directly return the response object
Browse files Browse the repository at this point in the history
  • Loading branch information
derekantrican committed Nov 17, 2023
1 parent cc03f3e commit 9f52409
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions ClockworkFramework.Core/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,25 @@ public static void WriteToConsoleWithColor(object obj, ConsoleColor color)
public static string ApiRequest(string url, HttpMethod method, Dictionary<string, string> headers = null,
Dictionary<string, string> parameters = null, HttpContent content = null)
{
return ApiRequest(new ApiRequestParams
var response = ApiRequest(new ApiRequestParams
{
Url = url,
Method = method,
Headers = headers,
Parameters = parameters,
Content = content,
});

using (var stream = response.Content.ReadAsStream())
{
using (var streamReader = new StreamReader(stream))
{
return streamReader.ReadToEnd();
}
}
}

public static string ApiRequest(ApiRequestParams parameters)
public static HttpResponseMessage ApiRequest(ApiRequestParams parameters)
{
using (var client = new HttpClient())
{
Expand All @@ -75,14 +83,7 @@ public static string ApiRequest(ApiRequestParams parameters)

request.Content = parameters.Content;

var response = client.Send(request);
using (var stream = response.Content.ReadAsStream())
{
using (var streamReader = new StreamReader(stream))
{
return streamReader.ReadToEnd();
}
}
return client.Send(request);
}
}

Expand Down

0 comments on commit 9f52409

Please sign in to comment.