Michael Davidovich · Oct 31, 2022

Using %session with /api/mgmnt/ Service generated classes

Sessions and specifically %session are paramount to our application to login users to the application (the Web Gateway user logs into the server and then users login to the application).  

When using /api/mgmnt/v2 to implement a spec first approach to REST API development, I am unclear how I can utilize sessions (i.e. %session) to work with our existing model (and I'm sure there are indeed better ways to do this, but we are just baby stepping right now). Much of the documentation say to make sure UseSession=1 in the dispatch class is set, which I've accomplished.  This seemed hopeful because when using /api/mgmt, the generated disp.cls extends %CSP.Rest which then provides the %session var.  However, the documentation is clear to not edit that class and only touch the impl.cls.  This class extends %REST so it doesn't seem to know or care about %CSP.Rest or %session (however, the disp.cls does call it).  Is there a way to bring this %session var into play since disp.cls calls impl.cls (without modifying disp.cls)?

I have read an article here that mentioned sessions in this context are only good for authentication (not data) however, I think that article meant authenticating into the IRIS server.  I am trying to authenticate into our application and keep our user alive (and, well, keep some session data alive too).

I realize it's not quite the paradigm for REST but I'm trying to move the needle without rewriting the whole thing or completely changing how we do things today.

$ZV: IRIS for Windows (x86-64) 2020.1.1 (Build 408U) Sun Mar 21 2021 22:04:09 EDT
0 153
Discussion (4)1
Log in or sign up to continue

Thanks, @Eduard Lebedyuk.  See above that I did set UseSession=1.

That's all the doc really explains. 

What next though?  How to utilize the session (%session) in impl.cls?  When I do this I get a  undefined error:

"error":"ERROR #5002: ObjectScript error: <UNDEFINED>zgetQuotes+1^API.QuoteLibrary.impl.1 *.Data(\"session\",1)"

I suppose another way of stating the issue.  The doc says you might want to use sessions to:

  • Preserve data across REST calls — in some cases, preserving data across REST calls may be necessary to efficiently meet your business requirements.

Well, I'm not finding an easy way to do this using spec first dev because the %session variable is undefined in the generated impl.cls. Even when I extend impl.cls to use %CSP.REST.  

@Eduard Lebedyuk I did catch one article you wrote that said sessions are basically only good for authentication (I assume you just meeting keep one logged into the IRIS server over the session), however since the doc does mention preserving data, I would like to see if I can utilize that feature.

For now I've reverted to the manual creation of rest services which now allows me the %session variable to use.