public async Task <List <string> > SearchJoke() { string searchedWord = Request.Form["word"]; var client = _httpClientFactory.CreateClient("API Client"); string url = client.BaseAddress + "search?term=" + searchedWord; string responseBody = await client.GetStringAsync(url); JokesModel jokes = JsonConvert.DeserializeObject <JokesModel>(responseBody); List <string> lista = new List <string>(); for (int i = 0; i < jokes.Results.Count; i++) { lista.Add(jokes.Results[i].Joke); } //użycie Linq to posortowania żartów od najkrótszego do najdłuższego return(lista.OrderBy(s => s.Length).ToList()); }
public async Task <List <string> > ReturnJokesCatergories() { var chuckNorrisJokeCategoriesAPIUrl = APIUrlDictionary.GetApiUrls()["chuckNorrisJokeCategoriesAPIUrl"]; using (var client = new HttpClient()) { var url = new Uri(chuckNorrisJokeCategoriesAPIUrl); var response = await client.GetAsync(url); string json; using (var content = response.Content) { json = await content.ReadAsStringAsync(); } var res = JokesModel.FromJson(json); List <string> list = new List <string>(res); return(list); } }