using System.Threading.Tasks;
using System.Collections.Generic;
public static void Main()
Console.WriteLine("Number of films: " + Run("Luke Skywalker"));
public static int Run(string character)
var t = Task.Run(() => GetResponseString(character));
RootObject root = JsonConvert.DeserializeObject<RootObject>(t.Result);
return root.results.FirstOrDefault().films.Count;
static async Task<string> GetResponseString(string character)
var response = string.Empty;
using (var client = new HttpClient())
HttpResponseMessage result = await client.GetAsync("https://challenges.hackajob.co/swapi/api/people/?search=" + character);
if (result.IsSuccessStatusCode)
response = await result.Content.ReadAsStringAsync();
public string name { get; set; }
public string height { get; set; }
public string mass { get; set; }
public string hair_color { get; set; }
public string skin_color { get; set; }
public string eye_color { get; set; }
public string birth_year { get; set; }
public string gender { get; set; }
public string homeworld { get; set; }
public List<string> films { get; set; }
public List<object> species { get; set; }
public List<string> vehicles { get; set; }
public List<string> starships { get; set; }
public DateTime created { get; set; }
public DateTime edited { get; set; }
public string url { get; set; }
public int count { get; set; }
public object next { get; set; }
public object previous { get; set; }
public List<Result> results { get; set; }