Skip to main content
Previous sectionNext section

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.”

Introduction

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 InterSystems IRIS license usage — if each REST call creates a new web session, it requires a separate InterSystems IRIS license. InterSystems IRIS frees the license after a brief timeout period. If you are making rare and infrequent REST calls, this is usually not a problem, but if you are making many REST calls in a brief time period, you can exceed the number of licenses available on your system. If you use the same web session for multiple REST calls, the session only consumes one license.

  • 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;
Copy code to clipboard

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.

Note:

When you recompile the specification class, the UseSession parameter is copied to the dispatch class, which causes the actual change in behavior.