Is there a way to get rid of the Task type on an object?

I am building my first full stack app where I am building a .NET core website and an API for it to make queries to the database.



I am having trouble converting the API returns into the proper formats that I need for the front end. I can't figure out how to convert Task<IEnumerable<Appetizer>> into List<Appetizer>. I've tried a few different solutions and no luck so far.

public class AppetizerService
{
        private List<Appetizer> appetizers = new List<Appetizer>();
    
        public static string BaseAddress = "http://127.0.0.1:5000";
        static readonly string Url = $"{BaseAddress}/";
    
        static HttpClient client = new HttpClient();
    
        public async Task InitializeAppetizerServiceAsync()
        {
                    this.appetizers =  getAppetizers();
            await Task.Delay(100);
        }
    
        public List<Appetizer> getAppetizers()
        {
            this.appetizers = getAllAppsFromApi();
    
            return this.appetizers;
        }


        public static async Task<IEnumerable<Appetizer>> getAllAppsFromApi()
        {
    
            string result = await client.GetStringAsync($"{Url}api/all_apps");

            var temp = JsonConvert.DeserializeObject<List<Appetizer>>(result);

            return temp;

        }
}
Was this page helpful?