static void Main(string[] args)
        {
            var    client       = new System.Net.Http.HttpClient();
            string response     = string.Empty;
            string authHeader   = string.Empty;
            string verb         = string.Empty;
            string resourceType = string.Empty;
            string resourceId   = string.Empty;
            string resourceLink = string.Empty;

            client.DefaultRequestHeaders.Add("x-ms-date", utc_date);
            client.DefaultRequestHeaders.Add("x-ms-version", "2015-08-06");

            //LIST all databases
            verb         = "GET";
            resourceType = "dbs";
            resourceId   = string.Empty;
            resourceLink = string.Format("dbs");

            authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");

            client.DefaultRequestHeaders.Remove("authorization");
            client.DefaultRequestHeaders.Add("authorization", authHeader);

            response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;

            //GET a database
            verb         = "GET";
            resourceType = "dbs";
            resourceLink = "dbs/" + databaseId;
            resourceId   = (idBased) ? resourceLink : databaseId.ToLowerInvariant();

            authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");

            client.DefaultRequestHeaders.Remove("authorization");
            client.DefaultRequestHeaders.Add("authorization", authHeader);

            response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;

            //LIST all collections
            verb         = "GET";
            resourceType = "colls";
            resourceLink = string.Format("dbs/{0}/colls", databaseId);
            resourceId   = (idBased) ? string.Format("dbs/{0}", databaseId) : databaseId.ToLowerInvariant();

            authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");

            client.DefaultRequestHeaders.Remove("authorization");
            client.DefaultRequestHeaders.Add("authorization", authHeader);

            response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;

            //GET a collections
            verb         = "GET";
            resourceType = "colls";
            resourceLink = string.Format("dbs/{0}/colls/{1}", databaseId, collectionId);
            resourceId   = (idBased) ? resourceLink : collectionId.ToLowerInvariant();

            authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");

            client.DefaultRequestHeaders.Remove("authorization");
            client.DefaultRequestHeaders.Add("authorization", authHeader);

            response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;

            //LIST all documents in a collection
            verb         = "GET";
            resourceType = "docs";
            resourceLink = string.Format("dbs/{0}/colls/{1}/docs", databaseId, collectionId);
            resourceId   = (idBased) ? string.Format("dbs/{0}/colls/{1}", databaseId, collectionId) : collectionId.ToLowerInvariant();

            authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");

            client.DefaultRequestHeaders.Remove("authorization");
            client.DefaultRequestHeaders.Add("authorization", authHeader);

            response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;

            //GET a document
            verb         = "GET";
            resourceType = "docs";
            resourceLink = string.Format("dbs/{0}/colls/{1}/docs/{2}", databaseId, collectionId, documentId);
            resourceId   = (idBased) ? resourceLink : documentId.ToLowerInvariant();

            authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");

            client.DefaultRequestHeaders.Remove("authorization");
            client.DefaultRequestHeaders.Add("authorization", authHeader);

            response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;

            //EXECUTE a query
            verb         = "POST";
            resourceType = "docs";
            resourceLink = string.Format("dbs/{0}/colls/{1}/docs", databaseId, collectionId);
            resourceId   = (idBased) ? string.Format("dbs/{0}/colls/{1}", databaseId, collectionId) : collectionId.ToLowerInvariant();

            authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");

            client.DefaultRequestHeaders.Remove("authorization");
            client.DefaultRequestHeaders.Add("authorization", authHeader);
            client.DefaultRequestHeaders.Add("x-ms-documentdb-isquery", "True");

            var qry = new SqlQuerySpec {
                query = "SELECT * FROM root"
            };
            var r = client.PostWithNoCharSetAsync(new Uri(baseUri, resourceLink), qry).Result;

            Console.WriteLine(r.Content.ToString());
        }