Kdb+ provides a basic implementation of a web server allowing browsing tables that exist on the server, performing queries and downloading data from a web browser. Kdb+ also provides calls to pull data via HTTP. We'll examing how to do this below:

Contents

  1. Connect to kdb+ Web Interface
  2. Query kdb+ from a Web Browser
  3. .z.ph HTTP event handler
  4. HTTP Requests - Download data from an internet address into kdb+

Connect to kdb+ Web Interface

To connect to a kdb+ server:

  1. First make sure you know the address of the server you want to connect to.
    Here we start a kdb process on our local machine port 5000 using the command q -p 5000
  2. Next open your web browser and enter the host and port of the kdb process. Ours is localhost:5000,
    Connect to kdb+ Server from Web Browser
Immediately you will be presented with a window with two panes
  • the left frame is a list of links to tables that exist
  • the right hand side will display any of the tables you click.

Query kdb+ from a Web Browser

To send a custom query to the server we use a /? followed by our query as shown:

query kdb+ Server from Web Browser

If you insert a filename with the ending .csv, .xls or .xml this will download a file for that query from the server in either csv/excel format.

save csv from kdb+ webserver

.z.ph http event handler

When an HTTP GET request is received, the request is processed by the .z.ph event handler. The argument it receives is a two item list of the form: ( request text ; request header ). Here I have saved it to a variable a:

You can override this function to provide your own html interface. Here's an example where we override .z.ph to provide a qStudio like web interface:

Similarly there is a .z.pp event handler for HTTP post events.

HTTP Requests

From kdb+ we can send HTTP requests to webservers. For example we can send a request to yahoo finance servers for a csv file they provide:

Let's wrap our http get in a function and then parse our data so we get a table:

This http querying works for any type of page, even plain webpages, and could be used to query REST api's etc.