Examples

Data API Quick Links

WICK API Quick Links

Retrieving list of alcoholic beverages in JSON format (filtering) (HTML, JavaScript, jQuery, Knockout)

Written by Jay Harris

Retrieving list of Disney movies in JSON format (paging) (HTML, JavaScript, jQuery, Knockout)

Written by Jay Harris

Retrieving list of presidents in JSON format (HTML, JavaScript, AngularJS)

Retrieving list of presidents in JSON format (HTML, JavaScript, jQuery, Knockout)

Retrieving list of The Beatles' albums in JSON format (HTML, JavaScript)

Retrieving list of presidents in XML format (HTML, JavaScript, jQuery)

Populating presidents dropdown list in XML format (HTML, JavaScript, jQuery)

Retrieving list of presidents in JSONP format (HTML, JavaScript, jQuery)

Populating states dropdown list in JSONP format (HTML, JavaScript, jQuery)

Retrieving list of presidents in TABLE format (HTML, JavaScript, jQuery)

Retrieving list of presidents in SELECT format (HTML, JavaScript, jQuery)

Retrieving list of presidents in RADIO format (HTML, JavaScript, jQuery)

Retrieving list of presidents in CHECKBOX format (HTML, JavaScript, jQuery)

Retrieving list of states in XML format (C#)


// variables
XmlDocument States = new XmlDocument();
string Url = "https://mysafeinfo.com/api/data?list=states&format=xml&alias=nm=name,ab=code,cp=capital,yr=year";

// request
States.Load(Url);

// iterate states collection
foreach (XmlElement s in States.SelectNodes("//s"))
{
    string.Format("{0}, {1}, {2}, {3}", s.GetAttribute("name"), s.GetAttribute("code"), s.GetAttribute("capital"), s.GetAttribute("year"));
}

Retrieving list of states in XML format (VB.Net)


'variables
Dim States As New XmlDocument()
Dim Url As String = "https://mysafeinfo.com/api/data?list=states&format=xml&alias=nm=name,ab=code,cp=capital,yr=year"

'request
States.Load(Url)

'iterate states collection
For Each s As XmlElement In States.SelectNodes("//s")
    String.Format("{0}, {1}, {2}, {3}", s.GetAttribute("name"), s.GetAttribute("code"), s.GetAttribute("capital"), s.GetAttribute("year"))
Next

Retrieving list of states in JSON format (C#)


// variables
string Result = string.Empty;
string Url = "https://mysafeinfo.com/api/data?list=states&format=json&alias=nm=name,ab=code,cp=capital,yr=year";
List<State> States = new List<State>();

// request
using (WebClient client = new WebClient())
{
    Result = client.DownloadString(Url);
}

// use Json.NET (Newtonsoft.Json) to deserialize json string into a strongly typed list of states
// https://www.nuget.org/packages/Newtonsoft.Json
States = Newtonsoft.Json.JsonConvert.DeserializeObject<List<State>>(Result);

// iterate states collection
foreach (State s in States)
{
    string.Format("{0}, {1}, {2}, {3}", s.name, s.code, s.capital, s.year);
}

// state class
public class State
{
    public string name = string.Empty;
    public string code = string.Empty;
    public string capital = string.Empty;
    public string year = string.Empty;
}

Retrieving list of presidents in CSV format (Java)


import java.io.*;
import java.net.URL;

public class ReadCSV {
    // url to web service
    final static String webSiteURL = "https://mysafeinfo.com/api/data?list=presidents&format=csv";

    // outfile file path
    final static String rawFileName = "c:\\temp\\presidents.csv";

    // main
    public static void main(String[] args) {
        // fetch our data and create a CSV file
        fetchData(webSiteURL);
    }

    // fetch data from web in CSV format
    private static void fetchData(String siteURL) {
        try {
            // open output file
            PrintWriter pw =  new PrintWriter(rawFileName);

            // define URL using website address
            URL serviceURL = new URL(siteURL);

            // define an input stream and reader
            InputStream is = serviceURL.openStream();
            InputStreamReader isr = new InputStreamReader(is, "UTF-8");

            // buffered reader let us read and process chunks of data at time
            BufferedReader br = new BufferedReader(isr);

            // create a variable to hold the contents from the buffer
            StringBuffer response = new StringBuffer();

            // fetch the next chunk of content
            String nextLineFromService = br.readLine();

            // keep reading and appending to the buffer
            while (nextLineFromService != null) {
                // to see what we are doing in the console
                System.out.println(nextLineFromService);

                // output line to file
                pw.println(nextLineFromService);
                nextLineFromService = br.readLine();
            }

            // dump the buffer to our content variable
            isr.close();
            pw.close();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
mysafeinfo.com