Process HTTP Post request and response

Hello,

I am trying to use kdb+ integrated web server to reply to custom Post request. In q there is a variable .z.pp responsible for handling Post requests. But there is not default handler for .z,pp. I should defined it by myself. Is there anywhere examples for .z.pp? 

The example that I am trying to implement :

Client send Post request with data in json format:

Header “POST /enroll HTTP/1.1” 200

Body {u’enroll_secret’: u’this_is_a_deployment_secret’, u’host_identifier’: u’YOURHOSTNAME.local’}

Server (kdb+) send Post response with data in json format:


{u’node_key’: u’this_is_a_node_secret’}

Using .h.hy to wrap the response body in valid HTTP headers, and .j.j to convert the response dictionary to JSON:

q)response:enlist[node_key]!enlist[“this_is_a_node_secret”]q)q).z.pp:{:.h.hy [txt;.j.j response]}

Testing with curl:

curl --data '' http://localhost:7863{"node_key":"this_is_a_node_secret"}

James

The request dictionary is already parsed for you (documentation: http://code.kx.com/q/ref/dotz/#zph-http-get). With the help of .j, it should not be hard to perform what you needed in the sample above.