RestApiRequester.cs 816 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Net.Http;
  3. using System.Text.Json;
  4. using System.Threading.Tasks;
  5. namespace sera_slackbot.Library
  6. {
  7. public class RestApiRequester
  8. {
  9. public async Task<dynamic> GetJson(string url)
  10. {
  11. var contentString = string.Empty;
  12. var client = new HttpClient();
  13. try
  14. {
  15. var response = await client.GetAsync(url);
  16. contentString = await response.Content.ReadAsStringAsync();
  17. return JsonSerializer.Deserialize<dynamic>(contentString);
  18. }
  19. catch (Exception e)
  20. {
  21. Console.WriteLine("Issue with making the curl; I tried " + url);
  22. Console.WriteLine(e.Message);
  23. }
  24. return contentString;
  25. }
  26. }
  27. }