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); } }
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; } })); }
public async Task <T> SendHttp <T>(ApiInfo apiInfo) { var response = await this.SendHttpAsResponse(apiInfo); return(await FromResponse <T>(response)); }
public Task SendHttp(ApiInfo apiInfo) { return(SendHttpAsResponse(apiInfo)); }