Beispiel #1
0
        private static async Task ReadChapterAsync()
        {
            WriteLine(nameof(ReadChapterAsync));
            var client   = new BookChapterClient(Addresses.BaseAddress);
            var chapters = await client.GetAllAsync(Addresses.BooksApi);

            Guid        id      = chapters.First().Id;
            BookChapter chapter = await client.GetAsync(Addresses.BooksApi + id);

            WriteLine($"{chapter.Number} {chapter.Title}");
            WriteLine();
        }
Beispiel #2
0
        private static async Task ReadNotExistingChapterAsync()
        {
            WriteLine(nameof(ReadNotExistingChapterAsync));
            string requestedIdentifier = Guid.NewGuid().ToString();

            try
            {
                var         client  = new BookChapterClient(Addresses.BaseAddress);
                BookChapter chapter = await client.GetAsync(Addresses.BooksApi + requestedIdentifier.ToString());

                WriteLine($"{chapter.Number} {chapter.Title}");
            }
            catch (HttpRequestException ex) when(ex.Message.Contains("404"))
            {
                WriteLine($"book chapter with the identifier {requestedIdentifier} not found");
            }
            WriteLine();
        }