Ejemplo n.º 1
0
        private static async Task ReadWithExtensionsSample()
        {
            var client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:11825");
            HttpResponseMessage response =
                await client.GetAsync("/api/BookChapters/3");

            BookChapter chapter =
                await response.Content.ReadAsAsync <BookChapter>();

            Console.WriteLine("{0}. {1}", chapter.Number, chapter.Title);
        }
Ejemplo n.º 2
0
        private static async Task UpdateSample()
        {
            var client = new HttpClient();

            client.BaseAddress = new Uri("http://120.27.7.115:81");

            var updatedChapter = new BookChapter
            {
                Title  = "Visual Studio 2013",
                Number = 17,
                Pages  = 50
            };

            await client.PutAsJsonAsync("/api/BookChapters/17", updatedChapter);

            await ReadArraySample();
        }
Ejemplo n.º 3
0
        private static async Task UpdateWithErrorSample()
        {
            try
            {
                var client = new HttpClient();
                client.BaseAddress = new Uri("http://120.27.7.115:81");

                var updatedChapter = new BookChapter
                {
                    Title  = "NotExisting",
                    Number = 88,
                    Pages  = 50
                };

                await client.PutAsJsonAsync("/api/BookChapters/88", updatedChapter);

                await ReadArraySample();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }