solidDB Help : Programming : solidDB HTTP SQL Access : Code samples:
  
Code samples:
Ruby
require 'net/https'
require 'openssl'

h = Net::HTTP.new('teuvo.solidtech.com', 1969)
h.use_ssl = true
h.ca_file = File.expand_path("C:\Users\teuvo\Desktop\HTTPS_demo\ruby_demo\server.crt")
h.verify_mode = OpenSSL::SSL::VERIFY_NONE

puts "Open connection"
resp, data = h.get('/open?username=dba&password=dba', nil )
puts "Code = #{resp.code}"
puts "Message = #{resp.message}"
mycookie = resp.response['set-cookie'].split('; ')[0]
puts resp.body

puts "Get SQL data"
resp, data = h.get('/sql/select+*+from+users', { 'Cookie' => mycookie } )

puts "Code = #{resp.code}"
puts "Message = #{resp.message}"
puts resp.body
GO
package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "net/http/cookiejar"
    "crypto/tls"
)

func main() {
     jar, err := cookiejar.New(nil)
     if err != nil {
          log.Fatal(err)
     }
    tlsConfig := &tls.Config{InsecureSkipVerify: true}    
    tr := &http.Transport{TLSClientConfig: tlsConfig}
    client := &http.Client{Jar: jar, Transport: tr}
   res, err := client.Get("https://teuvo.solidtech.com:1969/open?username=dba&password=dba")
     if err != nil {
          log.Fatal(err)
    }
    solidret, err := ioutil.ReadAll(res.Body)
    res.Body.Close()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s", solidret)

    res, err = client.Get("https://teuvo.solidtech.com:1969/sql/select+*+from+sys_users")
    if err != nil {
        log.Fatal(err)
    }
    solidret, err = ioutil.ReadAll(res.Body)
    res.Body.Close()
    if err != nil {
         log.Fatal(err)
    }
    fmt.Printf("%s", solidret)   x     
}
Python
import cookielib, urllib2
print 'Hello, Risto!'
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
r = opener.open("https://teuvo.solidtech.com:1969/open?username=dba&password=dba")
data = r.read()
print data

r = opener.open("https://teuvo.solidtech.com:1969/sql/select+*+from+users")
data = r.read()
print data

r = opener.open("http://teuvo.solidtech.com:1313/sql/select+*+from+sys_users")
data = r.read()
print data

r = opener.open("https://teuvo.solidtech.com:1969/sql/select+count(*)+from+tables")
data = r.read()
print data
HTML and Javascript
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta charset="utf-8" />
   <title></title>
   <style>
       #demo_input {
           float: left;
       }

       #examples {
           clear: both;
       }
   </style>
</head>
<body>

   <div id="header">
       <h2>solidDB html-interface test page</h2>
   </div>

   <div id="demo_input">
       <button type="button" onclick="sendURLGet()">Send URL (Get):</button>

       <p>URL:</p>
       <input type="text" name="urlToSolid" /></input>
       <p>Response from solidDB:</p>
       <div id="WebPageResponse"></div>
   </div>

   <div id="examples">
       <p>Opening connections:</p>
       <ul style="list-style-type: disc">
           <li>Open tls connection: URL = https://10.30.1.45:1969/open?username=dba&password=dba</li>
           <li>Open tcp connection: URL = http://10.30.1.45:1313/open?username=dba&password=dba</li>
       </ul>

       <p>Executing SQL statements:</p>
       <ul style="list-style-type: disc">
           <li>Resultset as json: URL = https://10.30.1.45:1969/sql/select+*+from+users</li>
       </ul>
   </div>

   <script>
       var req = new XMLHttpRequest();
       var url = "https://10.30.1.45:1969/open?username=dba&password=dba"
       req.open('GET', url, false);
       req.send(null);
       if (req.status == 200)
           document.getElementById("WebPageResponse").innerHTML = req.responseText;
       var headers = req.getAllResponseHeaders();
       alert(headers)
   </script>

   <script>
       function sendURLGet() {
           //var req = new XMLHttpRequest();
           url = urlToSolid.value + "?t=" + Math.random();

           req.onreadystatechange = function () {
               document.getElementById("WebPageResponse").innerHTML = "getting data";
               myFunction(req.responseText);
           }

           req.open("GET", url, true);
           req.send(null);
           document.getElementById("WebPageResponse").innerHTML = "sql sent";
           function myFunction(response) {
               alert("request status: " + req.status + "\n" + "request readyState: " + req.readyState)
               if (req.readyState == 4 && req.status == 200) {
                   document.getElementById("WebPageResponse").innerHTML = response;
                   var headers = req.getAllResponseHeaders();
                   alert(headers)
               }
               if (req.readyState == 4 && req.status == 400) {
                   document.getElementById("WebPageResponse").innerHTML = response;
                   var headers = req.getAllResponseHeaders();
                   alert(headers)
               }
           }
       }
   </script>

</body>
</html>
Go up to
solidDB HTTP SQL Access