renames. update default timeout to 30 secs
This commit is contained in:
parent
b14d017f43
commit
07ecc55433
@ -8,7 +8,7 @@ namespace BinaryDad.Extensions
|
|||||||
{
|
{
|
||||||
public class RestUtility
|
public class RestUtility
|
||||||
{
|
{
|
||||||
public const int DefaultTimeout = 5000;
|
public const int DefaultTimeout = 30000;
|
||||||
|
|
||||||
#region Get
|
#region Get
|
||||||
|
|
||||||
@ -18,20 +18,20 @@ namespace BinaryDad.Extensions
|
|||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="additionalHeaders"></param>
|
/// <param name="additionalHeaders"></param>
|
||||||
/// <param name="timeoutMs">Timeout of the request in milliseconds</param>
|
/// <param name="timeout">Timeout of the request in milliseconds</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static T Get<T>(string url, Dictionary<string, string> additionalHeaders = null, int timeoutMs = DefaultTimeout) => Send(url, HttpMethod.Get, typeof(T), null, additionalHeaders, timeoutMs).To<T>();
|
public static T Get<T>(string url, Dictionary<string, string> additionalHeaders = null, int timeout = DefaultTimeout) => Send(url, HttpMethod.Get, typeof(T), null, additionalHeaders, timeout).To<T>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes a GET request with optional headers
|
/// Invokes a GET request with optional headers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="additionalHeaders"></param>
|
/// <param name="additionalHeaders"></param>
|
||||||
/// <param name="timeoutMs">Timeout of the request in milliseconds</param>
|
/// <param name="timeout">Timeout of the request in milliseconds</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string Get(string url, Dictionary<string, string> additionalHeaders = null, int timeoutMs = DefaultTimeout) =>
|
public static string Get(string url, Dictionary<string, string> additionalHeaders = null, int timeout = DefaultTimeout) =>
|
||||||
// response type is always a string if no returnObjectType is used
|
// response type is always a string if no returnObjectType is used
|
||||||
Send(url, HttpMethod.Get, null, null, additionalHeaders, timeoutMs) as string;
|
Send(url, HttpMethod.Get, null, null, additionalHeaders, timeout) as string;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes a GET request with optional headers
|
/// Invokes a GET request with optional headers
|
||||||
@ -39,11 +39,9 @@ namespace BinaryDad.Extensions
|
|||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="returnObjectType"></param>
|
/// <param name="returnObjectType"></param>
|
||||||
/// <param name="additionalHeaders"></param>
|
/// <param name="additionalHeaders"></param>
|
||||||
/// <param name="timeoutMs">Timeout of the request in milliseconds</param>
|
/// <param name="timeout">Timeout of the request in milliseconds</param>
|
||||||
/// <param name="sleepDelayMs"></param>
|
|
||||||
/// <param name="retries"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static object Get(string url, Type returnObjectType, Dictionary<string, string> additionalHeaders = null, int timeoutMs = DefaultTimeout) => Send(url, HttpMethod.Get, returnObjectType, null, additionalHeaders, timeoutMs);
|
public static object Get(string url, Type returnObjectType, Dictionary<string, string> additionalHeaders = null, int timeout = DefaultTimeout) => Send(url, HttpMethod.Get, returnObjectType, null, additionalHeaders, timeout);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -56,9 +54,9 @@ namespace BinaryDad.Extensions
|
|||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="body"></param>
|
/// <param name="body"></param>
|
||||||
/// <param name="additionalHeaders"></param>
|
/// <param name="additionalHeaders"></param>
|
||||||
/// <param name="timeoutMs">Timeout of the request in milliseconds</param>
|
/// <param name="timeout">Timeout of the request in milliseconds</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static T Post<T>(string url, object body, Dictionary<string, string> additionalHeaders = null, int timeoutMs = DefaultTimeout) => Send(url, HttpMethod.Post, typeof(T), body, additionalHeaders, timeoutMs).To<T>();
|
public static T Post<T>(string url, object body, Dictionary<string, string> additionalHeaders = null, int timeout = DefaultTimeout) => Send(url, HttpMethod.Post, typeof(T), body, additionalHeaders, timeout).To<T>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes a POST request with optional headers
|
/// Invokes a POST request with optional headers
|
||||||
@ -66,11 +64,11 @@ namespace BinaryDad.Extensions
|
|||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="body"></param>
|
/// <param name="body"></param>
|
||||||
/// <param name="additionalHeaders"></param>
|
/// <param name="additionalHeaders"></param>
|
||||||
/// <param name="timeoutMs">Timeout of the request in milliseconds</param>
|
/// <param name="timeout">Timeout of the request in milliseconds</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string Post(string url, object body, Dictionary<string, string> additionalHeaders = null, int timeoutMs = DefaultTimeout) =>
|
public static string Post(string url, object body, Dictionary<string, string> additionalHeaders = null, int timeout = DefaultTimeout) =>
|
||||||
// response type is always a string if no returnObjectType is used
|
// response type is always a string if no returnObjectType is used
|
||||||
Send(url, HttpMethod.Post, null, body, additionalHeaders, timeoutMs) as string;
|
Send(url, HttpMethod.Post, null, body, additionalHeaders, timeout) as string;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes a POST request with optional headers
|
/// Invokes a POST request with optional headers
|
||||||
@ -79,11 +77,9 @@ namespace BinaryDad.Extensions
|
|||||||
/// <param name="returnObjectType"></param>
|
/// <param name="returnObjectType"></param>
|
||||||
/// <param name="body"></param>
|
/// <param name="body"></param>
|
||||||
/// <param name="additionalHeaders"></param>
|
/// <param name="additionalHeaders"></param>
|
||||||
/// <param name="timeoutMs">Timeout of the request in milliseconds</param>
|
/// <param name="timeout">Timeout of the request in milliseconds</param>
|
||||||
/// <param name="sleepDelayMs"></param>
|
|
||||||
/// <param name="retries"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static object Post(string url, Type returnObjectType, object body, Dictionary<string, string> additionalHeaders, int timeoutMs = DefaultTimeout) => Send(url, HttpMethod.Post, returnObjectType, body, additionalHeaders, timeoutMs);
|
public static object Post(string url, Type returnObjectType, object body, Dictionary<string, string> additionalHeaders, int timeout = DefaultTimeout) => Send(url, HttpMethod.Post, returnObjectType, body, additionalHeaders, timeout);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -97,9 +93,9 @@ namespace BinaryDad.Extensions
|
|||||||
/// <param name="method"></param>
|
/// <param name="method"></param>
|
||||||
/// <param name="body"></param>
|
/// <param name="body"></param>
|
||||||
/// <param name="additionalHeaders"></param>
|
/// <param name="additionalHeaders"></param>
|
||||||
/// <param name="timeoutMs">Timeout of the request in milliseconds</param>
|
/// <param name="timeout">Timeout of the request in milliseconds</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static T Send<T>(string url, HttpMethod method, object body = null, Dictionary<string, string> additionalHeaders = null, int timeoutMs = DefaultTimeout) => Send(url, method, typeof(T), body, additionalHeaders, timeoutMs).To<T>();
|
public static T Send<T>(string url, HttpMethod method, object body = null, Dictionary<string, string> additionalHeaders = null, int timeout = DefaultTimeout) => Send(url, method, typeof(T), body, additionalHeaders, timeout).To<T>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes a request with custom method/verb and optional headers
|
/// Invokes a request with custom method/verb and optional headers
|
||||||
@ -108,9 +104,9 @@ namespace BinaryDad.Extensions
|
|||||||
/// <param name="method"></param>
|
/// <param name="method"></param>
|
||||||
/// <param name="body"></param>
|
/// <param name="body"></param>
|
||||||
/// <param name="additionalHeaders"></param>
|
/// <param name="additionalHeaders"></param>
|
||||||
/// <param name="timeoutMs">Timeout of the request in milliseconds</param>
|
/// <param name="timeout">Timeout of the request in milliseconds</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string Send(string url, HttpMethod method, object body = null, Dictionary<string, string> additionalHeaders = null, int timeoutMs = DefaultTimeout) => Send(url, method, null, body, additionalHeaders, timeoutMs) as string;
|
public static string Send(string url, HttpMethod method, object body = null, Dictionary<string, string> additionalHeaders = null, int timeout = DefaultTimeout) => Send(url, method, null, body, additionalHeaders, timeout) as string;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes a request with custom method/verb and optional headers
|
/// Invokes a request with custom method/verb and optional headers
|
||||||
@ -120,18 +116,16 @@ namespace BinaryDad.Extensions
|
|||||||
/// <param name="returnObjectType"></param>
|
/// <param name="returnObjectType"></param>
|
||||||
/// <param name="body"></param>
|
/// <param name="body"></param>
|
||||||
/// <param name="additionalHeaders"></param>
|
/// <param name="additionalHeaders"></param>
|
||||||
/// <param name="timeoutMs">Timeout of the request in milliseconds</param>
|
/// <param name="timeout">Timeout of the request in milliseconds</param>
|
||||||
/// <param name="sleepDelayMs"></param>
|
|
||||||
/// <param name="retriesAllowed"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static object Send(string url, HttpMethod method, Type returnObjectType, object body = null, Dictionary<string, string> additionalHeaders = null, int timeoutMs = DefaultTimeout)
|
public static object Send(string url, HttpMethod method, Type returnObjectType, object body = null, Dictionary<string, string> additionalHeaders = null, int timeout = DefaultTimeout)
|
||||||
{
|
{
|
||||||
var serializedResponse = string.Empty;
|
var serializedResponse = string.Empty;
|
||||||
|
|
||||||
var request = WebRequest.CreateHttp(url);
|
var request = WebRequest.CreateHttp(url);
|
||||||
|
|
||||||
request.Method = method.ToString();
|
request.Method = method.ToString();
|
||||||
request.Timeout = timeoutMs;
|
request.Timeout = timeout;
|
||||||
request.ContentType = "application/json";
|
request.ContentType = "application/json";
|
||||||
request.Accept = "application/json, text/javascript, *; q=0.01"; // Accept is a reserved header, so you must modify it rather than add
|
request.Accept = "application/json, text/javascript, *; q=0.01"; // Accept is a reserved header, so you must modify it rather than add
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user