public async Task SendXmlToXDocumentAsync(HttpMethodTypes methodType) { FlurlHttp.Configure(c => c.HttpClientFactory = new EchoHttpClientFactory()); var method = HttpMethodByType[methodType]; var result = await "http://some.url" .SendXmlAsync(method, new TestModel { Number = 3, Text = "Test" }) .ReceiveXDocument(); AssertXDocument(result, 3, "Test"); }
public async Task SendXmlToModelAsync(HttpMethodTypes methodType) { FlurlHttp.Configure(c => c.HttpClientFactory = new EchoHttpClientFactory()); var method = HttpMethodByType[methodType]; var result = await new Url("https://some.url") .SendXmlAsync(method, new TestModel { Number = 3, Text = "Test" }) .ReceiveXml <TestModel>() .ConfigureAwait(false); AssertTestModel(result, 3, "Test"); }
public RouteDescriptorAttribute(string path, HttpMethodTypes type, string description) { Path = path; HttpMethodType = type; Description = description; }
/// <summary> /// Executes HttpClient query asynchronous. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryUrl">The query URL.</param> /// <param name="cancellationToken">Cancellation Token</param> /// <param name="content">The content.</param> /// <param name="method">The method .</param> /// <returns>Task<T>.</returns> internal static async Task <T> ExecuteQueryAsync <T>(StringBuilder queryUrl, CancellationToken cancellationToken, HttpContent content = null, HttpMethodTypes method = HttpMethodTypes.GET) { var authClient = new HttpClient { Timeout = TimeSpan.FromMilliseconds(30000) }; HttpResponseMessage result; switch (method) { case HttpMethodTypes.GET: result = await authClient.GetAsync(new Uri(queryUrl.ToString()), cancellationToken); break; case HttpMethodTypes.POST: result = await authClient.PostAsync(new Uri(queryUrl.ToString()), content, cancellationToken); break; case HttpMethodTypes.PUT: result = await authClient.PutAsync(new Uri(queryUrl.ToString()), content, cancellationToken); break; case HttpMethodTypes.DELETE: result = await authClient.DeleteAsync(new Uri(queryUrl.ToString()), cancellationToken); break; default: result = null; break; } if (result != null && result.StatusCode.ToString().ToLower().Equals("unauthorized")) { throw new HttpRequestException( "[Unauthorized] MeetupApi is unable to get this request, please re-login for renew your access token."); } else if (result != null && !result.StatusCode.ToString().ToLower().Equals("badgateway") && !result.StatusCode.ToString().ToLower().Equals("badrequest") && !result.StatusCode.ToString().ToLower().Equals("serviceunavailable")) { var data = await ProcessJson <T>(result.Content); return(data); } return(default(T)); }
/// <summary> /// Executes HttpClient query asynchronous. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryUrl">The query URL.</param> /// <param name="cancellationToken">Cancellation Token</param> /// <param name="content">The content.</param> /// <param name="method">The method .</param> /// <returns>Task<T>.</returns> internal static async Task <T> ExecuteQueryAsync <T>(StringBuilder queryUrl, CancellationToken cancellationToken, HttpContent content = null, HttpMethodTypes method = HttpMethodTypes.GET) { var authClient = new HttpClient { Timeout = TimeSpan.FromMilliseconds(30000) }; HttpResponseMessage result; switch (method) { case HttpMethodTypes.GET: result = await authClient.GetAsync(new Uri(queryUrl.ToString()), cancellationToken); break; case HttpMethodTypes.POST: result = await authClient.PostAsync(new Uri(queryUrl.ToString()), content, cancellationToken); break; case HttpMethodTypes.PUT: result = await authClient.PutAsync(new Uri(queryUrl.ToString()), content, cancellationToken); break; case HttpMethodTypes.DELETE: result = await authClient.DeleteAsync(new Uri(queryUrl.ToString()), cancellationToken); break; default: result = null; break; } if (result == null) { return(default(T)); } CheckIfCanProcessJson(result.StatusCode); var data = await ProcessJson <T>(result.Content); return(data); }