Using Web Sessions with REST
You can enable your REST service to use web sessions. This chapter describes why and how to do this.
This chapter assumes that you have previously generated REST service classes as described in the chapters “Using the /api/mgmnt Service to Create REST Services,” “Using the ^%REST Routine to Create REST Services,” or “Using the %REST.API Class to Create REST Services.”
One of the goals of REST is to be stateless; that is, no knowledge is stored on the server from one REST call to the next. Having a web session preserved across REST calls breaks the stateless paradigm, but there are two reasons why you might want to preserve a web session:
Minimize connection time — if each REST call creates a new web session, it needs to establish a new session on the server. By preserving a web session, the REST call connects faster.
Preserve data across REST calls — in some cases, preserving data across REST calls may be necessary to efficiently meet your business requirements.
Enabling a REST Service to Use Web Sessions
To enable using a single web session over multiple REST calls, set the UseSession parameter to 1 in the specification class. For example:
Parameter UseSession As Integer = 1;
Then recompile this class.
If UseSession is 1, InterSystems IRIS preserves a web session across multiple REST service calls. If the parameter is 0 (the default), InterSystems IRIS uses a new web session for each REST service call.
When you recompile the specification class, the UseSession parameter is copied to the dispatch class, which causes the actual change in behavior.