コード例 #1
0
        public static async Task <string> PutValue(int id, string value)
        {
            string nodePort = Nodes.Ports[ProxyModel.GetShardNumber(id)];

            string   url = "http://localhost:" + nodePort + "/database/" + id.ToString();
            string   responseContent;
            ValueDTO data = new ValueDTO {
                Value = value
            };
            string postBody = JsonConvert.SerializeObject(data);

            using (var client = new HttpClient())
            {
                var response = await client.PutAsync(url, new StringContent(postBody, Encoding.UTF8, "application/json"));

                string content = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    responseContent = JsonConvert.DeserializeObject(content).ToString();
                }
                else
                {
                    responseContent = value;
                }
                return(responseContent);
            }
        }
コード例 #2
0
        public static async Task <string> DeleteValue(int id)
        {
            string nodePort = Nodes.Ports[ProxyModel.GetShardNumber(id)];

            string url = "http://localhost:" + nodePort + "/database/" + id.ToString();

            using (var client = new HttpClient())
            {
                var response = await client.DeleteAsync(url);

                string content = await response.Content.ReadAsStringAsync();

                var responseContent = JsonConvert.DeserializeObject(content).ToString();
                return(responseContent);
            }
        }