.Net Sample

Add authentication information to request headers

GetHttpClient(), GetAsync(),GetAsyncCall() are defined in WebAPIProxy class
Sample:
        private string baseAddress = “http://demo-api.fmpilot2.com/Vendor/api/”
        private const string authTokenKey = "authenticationToken"; 
        private const string clientKey = "callingClient";
        private const string domainKey = "actingDomain";

        private HttpClient GetHttpClient(string authTokenValue, string clientValue, string domainValue, string contentType)
        {
             HttpClient client = new HttpClient();

             // Set the Header values
             client.DefaultRequestHeaders.Accept.Clear();
             client.DefaultRequestHeaders.Add(authTokenKey, authTokenValue);
             client.DefaultRequestHeaders.Add(clientKey, clientValue);
             client.DefaultRequestHeaders.Add(domainKey, domainValue);
             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

             // Set the base address
             client.BaseAddress = new Uri(baseAddress);
             return client;
        }

Creating WorkOrder Object

Sample:
        public class WO
        {
            public string WorkOrderNumber { get; set; }
            public string Type { get; set; }
            public string Status { get; set; }
            public string Description { get; set; }
            public string Priority { get; set; }
            public DateTime? DateReported { get; set; }
            public DateTime? DateModified { get; set; }
            public DateTime? TargetDate { get; set; }
            public DateTime? ScheduledStartDateTime { get; set; }
            public DateTime? ScheduledCompleteDateTime { get; set; }
            public DateTime? ActualStartDateTime { get; set; }
            public DateTime? ActualCompleteDateTime { get; set; }
            public string RequestingContact { get; set; }
            public string AlternateContact { get; set; }
            public string RequestType { get; set; }
            public string RequestCode { get; set; }
            public decimal DNE { get; set; }
            public Location Location { get; set; }
            public Equipment Equipment { get; set; }
            public Cause Cause { get; set; }
            public Remedy Remedy { get; set; }
        }
    
        

Creating Result Class

Sample:
        public class WebApiResult<T>
        {
          public System.Net.HttpStatusCode StatusCode { get; set; }
          public string ErrorMessage { get; set; }
          public T Result { get; set; }
        }
                

Executing WorkOrder(GET api/WorkOrders/{id})

Sample:
        WebAPIProxy webAPIProxy = new WebAPIProxy();
        WebApiResult<WO> result = webAPIProxy.GetAsync<WO>(authTokenValue, clientValue, domainValue, "WorkOrders/" + txtWONumber.Text, "application/json");
        
        public WebApiResult<T> GetAsync<T>(string authTokenValue, string clientValue, string domainValue, string actionName,string contentType)
        {
            WebApiResult<T> output = new WebApiResult<T>();
            try 
            {
                var result = GetAsyncCall<T>(authTokenValue, clientValue, domainValue, actionName, contentType);
                result.Wait();
                return result.Result;
            }
            catch(Exception e)
            {
                output.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                output.ErrorMessage = NoErrorMessage;
                return output;
            }
        }

        private async Task<WebApiResult <T>> GetAsyncCall<T>(string authTokenValue, string clientValue, string domainValue,string actionName, string contentType)
        {
            Func <Task<WebApiResult <T>>> valueFactory = async () =>
            {
                WebApiResult<T> output = new WebApiResult<T>();
                HttpClient client = GetHttpClient(authTokenValue, clientValue, domainValue, contentType);
                HttpResponseMessage response = await client.GetAsync(actionName).ConfigureAwait(false);
                output.StatusCode = response.StatusCode;
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    output.Result = await response.Content.ReadAsAsync<T>();
                else
                {
                    output.ErrorMessage = await response.Content.ReadAsStringAsync();
                    if (string.IsNullOrWhiteSpace(output.ErrorMessage))
                    {
                        output.ErrorMessage = NoErrorMessage;
                    }
                }
                return output;
            };