コード例 #1
0
ファイル: ApiClient.cs プロジェクト: MrJohnB/RunLog
        /// <summary>
        /// Call API to create a new object.
        /// </summary>
        /// <typeparam name="T">Object type for payload sent and return type</typeparam>
        /// <param name="requestUri">URI of the controller and rest of route</param>
        /// <param name="payload">Object instance to serialze and send</param>
        /// <returns>Object that was created by the API (includes the Id field value)</returns>
        public async Task <T> CreateAsync <T>(string requestUri, T payload)
        {
            var httpResponseMessage = await _restHttpClient.PostAsync(requestUri, payload);

            if (!httpResponseMessage.IsSuccessStatusCode)
            {
                throw new Exception($"The POST HTTP response was not successful.  Status code: '{httpResponseMessage.StatusCode}'.  Reason phrase: '{httpResponseMessage.ReasonPhrase}'.");
            }

            string content = await httpResponseMessage.Content.ReadAsStringAsync();

            return(_serializer.Deserialize <T>(content));
        }
コード例 #2
0
 /// <summary>
 /// Отправить данные асинхронно
 /// </summary>
 public async Task <IResultValue <string> > PostAsync(TDomain domain) =>
 await _transferConverter.ToTransfer(domain).
 ToJsonTransfer().
 ResultValueBindOkAsync(json =>
                        RestHttpClient.PostAsync(RestRequest.PostRequest(ControllerName), json));