Search code examples
apirestcurlkdb

How to create a kdb rest api


I am looking to create a rest api in kdb+ / q. Let's say my data is coming from some function .ns.func. Currently, I have something like:

.ns.zphOrig:.z.ph;
.ns.zphWrapper:{[zph; x]
   if[(x 0) like "*getData*"; :.h.hy[`json] .j.j .ns.func[x]];
   ret zph;
   ret}
.z.ph:.ns.zphWrapper[.ns.zphOrig];

With this, if I go to my page, let's say at "http://localhost.com:6789?getData&name=rob" then I will get the data in the correct json format. However, when I try to connect any other way, KDB seems to not see there was a request made at all and I get a 401 error.

I have also tried the following, still getting a 401 error with no sign of traffic.

.z.ws:{[x] neg[.z.w] .j.j .ns.func[x]}

When this is done, I will then connect to a C# program. Also, I cannot use any external libraries and I am using version 3.6. Thanks for any help!


Solution

  • The problem I was having was rooted in permissioning. The actual api was working fine once I cleared that up.