예제 #1
0
        protected virtual async Task <HttpResponseMessage> SendHttpAsResponse(ApiInfo apiInfo)
        {
            _ = apiInfo ?? throw new ArgumentNullException(nameof(apiInfo));

            using (var request = new HttpRequestMessage())
            {
                request.Method     = apiInfo.Method;
                request.RequestUri = BuildRequestUri(apiInfo);
                request.Content    = apiInfo.Body;

                this.AppendAttributeHeaders(request);
                this.AppendRestInfoHeaders(request);
                this.AppendRequestHeaders(apiInfo, request);

                var response = await httpClient.SendAsync(request);

                return(response);
            }
        }
예제 #2
0
 private string GetTranslatedPath(ApiInfo apiInfo)
 {
     // replace {key},{key:int},{age:range(18,120)},{ssn:regex(^\d{{3}}-\d{{2}}-\d{{4}}$)}
     if (apiInfo.Route == null)
     {
         return(apiInfo.Path);
     }
     return(Regex.Replace(apiInfo.Path ?? string.Empty, "\\{(?<nm>\\w+)(\\?)?(:.+)?\\}", (m) =>
     {
         var nm = m.Groups["nm"].Value;
         if (apiInfo.Route.TryGetValue(nm, out string value))
         {
             return UrlEncoder.Default.Encode(value);
         }
         else
         {
             return m.Value;
         }
     }));
 }
예제 #3
0
        public async Task <T> SendHttp <T>(ApiInfo apiInfo)
        {
            var response = await this.SendHttpAsResponse(apiInfo);

            return(await FromResponse <T>(response));
        }
예제 #4
0
 public Task SendHttp(ApiInfo apiInfo)
 {
     return(SendHttpAsResponse(apiInfo));
 }