コード例 #1
0
        public RestApi(RESTService service, string title, string description, string method, string resourceFormat, Type resultType)
        {
            Service         = service;
            Title           = title;
            Description     = description;
            Method          = method;
            ResourceFormat  = resourceFormat;
            QueryParameters = string.Empty;
            ResultType      = resultType;

            Headers           = new ObservableDictionary <string, string>();
            Headers["Accept"] = "application/json";

            BodyProperties = new ObservableDictionary <string, object>();
        }
コード例 #2
0
        // GET
        public async Task <JObject> GetAsync(Uri requestUri, ObservableDictionary <string, string> headers)
        {
            HttpClient httpClient = await this.GetWebRequestAsync(requestUri);

            AddHeaders(httpClient, headers);

            // Ensure that we don't get a cached response
            httpClient.DefaultRequestHeaders.IfModifiedSince = DateTime.UtcNow;

            // Call the service and GET the response
            HttpResponseMessage httpResponse = await httpClient.GetAsync(requestUri);

            var responseText = await httpResponse.Content.ReadAsStringAsync();

            LogResponse(httpResponse, string.Empty, responseText);
            EnsureSuccessStatusCode(requestUri.LocalPath, httpResponse);

            // Read and parse the response
            return(JObject.Parse(responseText));
        }
コード例 #3
0
        // Patch
        public async Task <JObject> PatchAsync(Uri requestUri, ObservableDictionary <string, string> headers, string body)
        {
            HttpClient httpClient = await this.GetWebRequestAsync(requestUri);

            AddHeaders(httpClient, headers);

            var request = new HttpRequestMessage(new HttpMethod("PATCH"), requestUri)
            {
                Content = new StringContent(body, Encoding.UTF8, "application/json")
            };

            // Call the service and GET the response
            HttpResponseMessage httpResponse = await httpClient.SendAsync(request);

            var responseText = await httpResponse.Content.ReadAsStringAsync();

            LogResponse(httpResponse, body, responseText);
            EnsureSuccessStatusCode(requestUri.LocalPath, httpResponse);

            // Parse the response
            return(JObject.Parse(responseText));
        }