public async Task <bool> IsFamous(string travellerName) { var httpClient = new HttpClient(); string json = await httpClient.GetStringAsync("https://swapi.dev/api/people/?search=" + travellerName); PersonResults personResults = JsonConvert.DeserializeObject <PersonResults>(json); return(personResults.results.Where(x => x.name.ToLower() == travellerName.ToLower()).Any()); }
public async Task <List <Spaceship> > GetSwapiSpaceships(string travellerName) { List <Spaceship> spaceships = new List <Spaceship>(); var httpClient = new HttpClient(); string json = await httpClient.GetStringAsync("https://swapi.dev/api/people/?search=" + travellerName); PersonResults personResults = JsonConvert.DeserializeObject <PersonResults>(json); List <string> spaceShipUrls = personResults.results.Where(x => x.name.ToLower() == travellerName.ToLower()).FirstOrDefault().starships; foreach (string spaceShipUrl in spaceShipUrls) { string spaceshipjson = await httpClient.GetStringAsync(spaceShipUrl); Starship starship = JsonConvert.DeserializeObject <Starship>(spaceshipjson); spaceships.Add(new Spaceship() { Name = starship.name, Length = starship.length }); } return(spaceships); }