shabiel / M-Web-Server

A YottaDB and Caché compatible HTTP server
Apache License 2.0
24 stars 19 forks source link

Advanced Rest Server Functionality #11

Closed sumeetchhetri closed 5 years ago

sumeetchhetri commented 5 years ago

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

shabiel commented 5 years ago

Let me add Christopher to this. It sounds interesting. It's a re-design of how passing parameters work. Right now we do not pass parameters as a formal list; but rather by reference.

I am on vacation right now; and I will have to look deeper into this.

--Sam

On Fri, Dec 21, 2018 at 7:46 AM Sumeet Chhetri notifications@github.com wrote:

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,1,"TYPE")=0 ^%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,2,"TYPE")=0 ^%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,3,"TYPE")=0 ^%W(17.6001,4,0)="GET" ^%W(17.6001,4,1)="get" ^%W(17.6001,4,2)="get^Test" ^%W(17.6001,4,"TYPE")=4 ^%W(17.6001,4,"TYPE",0)="q:q1" ^%W(17.6001,4,"TYPE",1)="h:h1" ^%W(17.6001,4,"TYPE",2)="req:" ^%W(17.6001,4,"TYPE",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,"TYPE")=6 ^%W(17.6001,5,"TYPE",0)="q:q1" ^%W(17.6001,5,"TYPE",1)="f:f1" ^%W(17.6001,5,"TYPE",2)="h:h1" ^%W(17.6001,5,"TYPE",3)="req:" ^%W(17.6001,5,"TYPE",4)="res:" ^%W(17.6001,5,"TYPE",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


You can view, comment on, or merge this pull request online at:

https://github.com/shabiel/M-Web-Server/pull/11

Commit Summary

Advanced Rest Server Functionality

File Changes

M src/VPRJRSP.m (108)

Patch Links:

https://github.com/shabiel/M-Web-Server/pull/11.patch https://github.com/shabiel/M-Web-Server/pull/11.diff

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

ChristopherEdwards commented 5 years ago

Interesting. I too have to take a deeper look.

shabiel commented 5 years ago

I took a first quick look today. I thought about it, and there are two things I thought would be really important:

  1. Backwards compability
  2. Global needs to be Fileman compatible, so that we can enter/edit data using Fileman.

Looks like it is backwards compatible (hurray) but the "TYPE" entries in the global are not Fileman compatible.

The "TYPE" nodes needs to be a Fileman header node; and each entry needs to be "TYPE",1,0)=... "TYPE",2,0)=...

Christopher, when you get a chance, can you do a quick review?

--Sam

On Fri, Dec 21, 2018 at 9:53 AM Christopher Edwards notifications@github.com wrote:

Interesting. I too have to take a deeper look.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

shabiel commented 5 years ago

I had another thought--when we convert it to a Fileman multiple, the header of the multiple won't mean anything anymore (so we can't have 0 or 1). So, the "TYPE" should be renamed "PARAMS", and we will merge the params array.

--Sam

sumeetchhetri commented 5 years ago

Thanks @shabiel, I have made the suggested changes. Just to be clear, I have a very basic understanding of Vista and don't completely understand Fileman yet, but still have tried to provide a fix as per my understanding, please review and let me know if there's anything more required to be done. (Would you please enlighten me on the terms Fileman header and Fileman multiple)

shabiel commented 5 years ago

Sumeet,

It's hard to explain Fileman compatiblity if you are not very familiar with Fileman. It's described here: http://www.hardhats.org/fileman/pm/gfs_frm.htm. Bascially, there are two things to understand:

The file comes with a data dictionary as well that needs to be updated; which is too hard for you to do if you have never done it before.

Here's what I will do: given everything I have seen, I will take your changes in. I think your idea is sound, and you preserved backwards compatibility. However, I need to redo the data structure so that it's Fileman compatible--especially so that you can use Fileman to add/edit the data rather than setting the entries using a global.

I am busy with something else right now; but I am shooting to take your pull request by the end of the year. If I don't have time to do that, I will let you know.

--Sam

On Wed, Dec 26, 2018 at 9:05 PM Sumeet Chhetri notifications@github.com wrote:

Thanks @shabiel, I have made the suggested changes. Just to be clear, I have a very basic understanding of Vista and don't completely understand Fileman yet, but still have tried to provide a fix as per my understanding, please review and let me know if there's anything more required to be done. (Would you please enlighten me on the terms Fileman header and Fileman multiple)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

shabiel commented 5 years ago

Code was re-implemented in branch 1-0-rewrite. Current code did not work.