title: Easy way to call REST API for c#?
body: <p>I am coming from JS and learning C# and I am trying to call to an API, I am having issues with the way I am calling it now and data seems to keep coming back as null. Can anyone help? Also is there an easier way to call an API with a library similar to Axios in JS? Everything with C# seems to be SO involved for even small tasks and its kind of a annoying, but I am going to keep trying.</p>
  <p>This is the error I get for @Model.FullList:</p>
  <p>&quot;System.NullReferenceException: 'Object reference not set to an instance of an object.'</p>
  <p>Microsoft.AspNetCore.Mvc.Razor.RazorPage.Model.get returned null.&quot;</p>
  <p>Here is the ViewModel and View
  ViewModel</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net.Http;
  using System.Threading.Tasks;
  
  namespace WebApplication1.Models
  {
      public class MissingPersonsModel
      {
          public string FullList { get; set; }
  
          public async Task GetMissingPeople()
          {
              var client = new HttpClient();
  
              try
              {
                  HttpResponseMessage response = await client.GetAsync(&quot;https://fbimissingpersonapi.azurewebsites.net/v1/all&quot;);
                  response.EnsureSuccessStatusCode();
                  string responseBody = await response.Content.ReadAsStringAsync();
  
                  FullList = responseBody;
  
                  Console.WriteLine(responseBody);
              }
              catch (HttpRequestException e)
              {
                  Console.WriteLine(&quot;\nException Caught!&quot;);
                  Console.WriteLine(&quot;Message :{0} &quot;, e.Message);
              }
          }
      }
  }
  
  </code></pre>
  <p>View</p>
  <pre><code>@model WebApplication1.Models.MissingPersonsModel
  
  @{
      ViewData[&quot;Title&quot;] = &quot;MissingPersons&quot;;
  }
  
  &lt;h1&gt;MissingPersons&lt;/h1&gt;
  
  
  &lt;div&gt;
      @Model.FullList
  &lt;/div&gt;
  
  &lt;div&gt;
      &lt;a asp-action=&quot;Index&quot;&gt;Back to List&lt;/a&gt;
  &lt;/div&gt;
  
  @section Scripts {
      @{await Html.RenderPartialAsync(&quot;_ValidationScriptsPartial&quot;);}
  }
  
  </code></pre>