Example #1
0
        public async Task <int> SumAsync(int[] numbers)
        {
            using (var httpClient = new HttpClient())
            {
                var requestDto = new CalcService_Sum_RequestDto()
                {
                    numbers = numbers
                };
                var json     = JsonSerializer.Serialize(requestDto);
                var content  = new StringContent(json, Encoding.UTF8, "application/json");
                var response = await httpClient.PostAsync(ApiUrl + "/api/CalcService/Sum", content);

                string jsonResponse = await response.Content.ReadAsStringAsync();

                var result = JsonSerializer.Deserialize <int>(jsonResponse, new JsonSerializerOptions()
                {
                    PropertyNameCaseInsensitive = true
                });
                return(result);
            }
        }
        public async Task <ActionResult <int> > SumAsync([FromBody] CalcService_Sum_RequestDto request)
        {
            var result = await this.CalcService.SumAsync(request.numbers);

            return(Ok(result));
        }