Skip to content

Advanced Rest Server Functionality

Created by: sumeetchhetri

Most restful frameworks/servers have this concept of mapping arguments coming in the request object (form param, header, query param, body, or contextual parameters like request/response) directly to the matched service function arguments, This PR enhances the existing Server code to add this conceptual layer, It achieves this by introducing new global entries to the ^%W(17.6001) file. I have tested this by directly invoking

s HTTPREQ("path")="get" s HTTPREQ("method")="GET" s HTTPREQ("query")="q1=Hello%20" s HTTPREQ("header","h1")="World!!" N HTTPRSP DO RESPOND^VPRJRSP

I get valid response parameters in the HTTPRSP variable, but the same does not work when i invoke curl -vvv http://localhost:9080/get?q1=q

Add support for Formal method parameters that can be passed to the actual mumps routine whether it is a query param, a form param, a header param, a context param(request/response) or a body param

Add these Global entries ^%W(17.6001,0)="WEB SERVICE URL HANDLER^17.6001S" ^%W(17.6001,1,0)="GET" ^%W(17.6001,1,1)="xml" ^%W(17.6001,1,2)="XML^VPRJRSP" ^%W(17.6001,2,0)="GET" ^%W(17.6001,2,1)="r/{routine?.1""%25"".32AN}" ^%W(17.6001,2,2)="R^%W0" ^%W(17.6001,3,0)="GET" ^%W(17.6001,3,1)="filesystem/" ^%W(17.6001,3,2)="FILESYS^%W0" ^%W(17.6001,3,"AUTH")=1 ^%W(17.6001,4,0)="GET" ^%W(17.6001,4,1)="get" ^%W(17.6001,4,2)="get^Test" ^%W(17.6001,4,"PARAMS",0)="q:q1" ^%W(17.6001,4,"PARAMS",1)="h:h1" ^%W(17.6001,4,"PARAMS",2)="req:" ^%W(17.6001,4,"PARAMS",3)="res:" ^%W(17.6001,5,0)="POST" ^%W(17.6001,5,1)="post" ^%W(17.6001,5,2)="post^Test" ^%W(17.6001,5,"PARAMS",0)="q:q1" ^%W(17.6001,5,"PARAMS",1)="f:f1" ^%W(17.6001,5,"PARAMS",2)="h:h1" ^%W(17.6001,5,"PARAMS",3)="req:" ^%W(17.6001,5,"PARAMS",4)="res:" ^%W(17.6001,5,"PARAMS",5)="body:" ^%W(17.6001,"B","GET","filesystem/","FILESYS^%W0",3)="" ^%W(17.6001,"B","GET","get","get^Test",4)="" ^%W(17.6001,"B","GET","r/{routine?.1""%25"".32AN}","R^%W0",2)="" ^%W(17.6001,"B","GET","xml","XML^VPRJRSP",1)="" ^%W(17.6001,"B","POST","post","post^Test",5)=""

Create a routine named Test.m Test ; POST /post?q1=q ; Headers: ; h1: h ; Content-Type: application/x-www-form-urlencoded ; Body: ; f1=value ; Response: ; {"q1": "q","f1": "value","h1": "h"} post(q1,f1,h1,creq,cres,bod) s cres("mime")="application/json" s cres="{""q1"":"""q1""",""f1"":"""f1""",""h1"":"""h1"""}" s cres("header","custom")="Custom" Q ; GET /get?q1=q ; Headers: ; h1: h ; Response: ; {"q1": "q","h1": "h"} get(q1,h1,creq,cres) s cres("mime")="application/json" s cres="{""q1"":"""q1""",""h1"":"""h1"""}" s cres("header","custom")="Custom" Q

Merge request reports