#region API Calls
#region GET
public static HttpResponseMessage CallGETAPI(String uri, IEnumerable<dynamic> Params)
{
try
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (HttpContext.Current.Session["Token"] != null && HttpContext.Current.Session["Token"] != "")
client.DefaultRequestHeaders.Add("X-My-Secret-Token", HttpContext.Current.Session["Token"].ToString());
return client.GetAsync(BaseAddress + "api/" + uri).Result;
}
}
catch (Exception ex)
{
LogException("Call GET API ", ex.ToString());
return new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.InternalServerError };
}
}
#endregion GET
#region POST
public static HttpResponseMessage CallPOSTAPI(String uri, Object Params)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (HttpContext.Current.Session["Token"] != null && HttpContext.Current.Session["Token"].ToString() != "")
client.DefaultRequestHeaders.Add("X-My-Secret-Token", HttpContext.Current.Session["Token"].ToString());
return client.PostAsJsonAsync(BaseAddress + "api/" + uri ,Params).Result;
}
}
#endregion
#region PUT
public static HttpResponseMessage CallPUTAPI(String uri, Object Params)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (HttpContext.Current.Session["Token"] != null && HttpContext.Current.Session["Token"].ToString() != "")
client.DefaultRequestHeaders.Add("X-My-Secret-Token", HttpContext.Current.Session["Token"].ToString());
return client.PutAsJsonAsync(BaseAddress + "api/" + uri, Params).Result;
}
}
#endregion PUT
#region DELETE
public static HttpResponseMessage CallDeleteAPI(String uri)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (HttpContext.Current.Session["Token"] != null && HttpContext.Current.Session["Token"].ToString() != "")
client.DefaultRequestHeaders.Add("X-My-Secret-Token", HttpContext.Current.Session["Token"].ToString());
return client.DeleteAsync(BaseAddress + "api/" + uri).Result;
}
}
#endregion DELETE
#endregion
#region GET
public static HttpResponseMessage CallGETAPI(String uri, IEnumerable<dynamic> Params)
{
try
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (HttpContext.Current.Session["Token"] != null && HttpContext.Current.Session["Token"] != "")
client.DefaultRequestHeaders.Add("X-My-Secret-Token", HttpContext.Current.Session["Token"].ToString());
return client.GetAsync(BaseAddress + "api/" + uri).Result;
}
}
catch (Exception ex)
{
LogException("Call GET API ", ex.ToString());
return new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.InternalServerError };
}
}
#endregion GET
#region POST
public static HttpResponseMessage CallPOSTAPI(String uri, Object Params)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (HttpContext.Current.Session["Token"] != null && HttpContext.Current.Session["Token"].ToString() != "")
client.DefaultRequestHeaders.Add("X-My-Secret-Token", HttpContext.Current.Session["Token"].ToString());
return client.PostAsJsonAsync(BaseAddress + "api/" + uri ,Params).Result;
}
}
#endregion
#region PUT
public static HttpResponseMessage CallPUTAPI(String uri, Object Params)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (HttpContext.Current.Session["Token"] != null && HttpContext.Current.Session["Token"].ToString() != "")
client.DefaultRequestHeaders.Add("X-My-Secret-Token", HttpContext.Current.Session["Token"].ToString());
return client.PutAsJsonAsync(BaseAddress + "api/" + uri, Params).Result;
}
}
#endregion PUT
#region DELETE
public static HttpResponseMessage CallDeleteAPI(String uri)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (HttpContext.Current.Session["Token"] != null && HttpContext.Current.Session["Token"].ToString() != "")
client.DefaultRequestHeaders.Add("X-My-Secret-Token", HttpContext.Current.Session["Token"].ToString());
return client.DeleteAsync(BaseAddress + "api/" + uri).Result;
}
}
#endregion DELETE
#endregion