public async static Task <List <Drink> > GetCocktailsOptionalAlcoholic() { try { String url = String.Format("https://www.thecocktaildb.com/api/json/v1/{0}/filter.php?a=Optional_alcohol", APIKEY); string result; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Accept", "application/json"); result = await client.GetStringAsync(url); } RootObjectDrinks rootObject = JsonConvert.DeserializeObject <RootObjectDrinks>(result); List <Drink> drinks = rootObject.drinks.ToList(); return(drinks); } catch (Exception e) { Debug.WriteLine(e.Message); Debug.WriteLine(e); } return(null); }
public async static Task <List <Drink> > getCocktailByGlass(string glass) { String url = String.Format("https://www.thecocktaildb.com/api/json/v1/{0}/filter.php?g={1}", APIKEY, glass); string result; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Accept", "application/json"); result = await client.GetStringAsync(url); } RootObjectDrinks rootobject = JsonConvert.DeserializeObject <RootObjectDrinks>(result); List <Drink> drinks = rootobject.drinks.ToList(); return(drinks); }
public async static Task <RootObjectDrinks> GetCocktailsById(string Id) { try { String url = String.Format("https://www.thecocktaildb.com/api/json/v1/{0}/lookup.php?i={1}", APIKEY, Id); string result; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Accept", "application/json"); result = await client.GetStringAsync(url); } RootObjectDrinks rootObject = JsonConvert.DeserializeObject <RootObjectDrinks>(result); return(rootObject); } catch (Exception e) { Debug.WriteLine(e.Message); Debug.WriteLine(e); } return(null); }