Michael Davidovich · Jul 29

Opinions on CSP methods to REST services?

What are other's thoughts, opinions and experiences going from CSP to RESTful services, specifically when it comes to reusing code in CSP files?

One could define a method in CSP as follows:

<script language="cache" method="SubmitSomethingAwesome" arguments="aswesomeId:%Numeric"> 

And it's generated in csp.mycsppage.cls ascsp.mycsppage.SubmitSomethingAwesome(awesomeId as %Numeric).

Have people had success defining there rest call by calling the generated CSP classmethod?

Things that work well I've found:

- Procedure block is off so you can easily pass the symbol table around from the REST implementation method to the CSP class method (often there's a lot to be setup before making the call to the class method.

- The obvious pro: you don't have to rewrite code or copy and paste it to a new method.

- Debugging can be simple . . . (see below as well) - since they are methods called from the client, you don't pass in objects, just strings so it's easier to debug in VSCode or command line.

Things that don't work so well:

- You will still have to maintain a CSP page for the life of the REST implementation until you just decide to refactor.  That said the <script> tag with the method isn't really any different than a method in a class file.

- Debugging is a bummer - because the procedure block is off it's hard to know which variables you are missing and when something bombs it's hard to track down the error.

I have to imagine this has been discussed on here before but I haven't found it yet.  Please link if you know otherwise I look forward to hearing thoughts!

0 165
Discussion (3)2
Log in or sign up to continue

You can probably make that work, but why not put the method in a %CSP.REST class to start with and have the CSP page call it? That seems more in line with the way those things are meant to be used.

@David Hockenbroch 


I think the major assumption I forgot to mentioned was that this is an existing web app built on CSP that we would like to modernized with REST APIs.  

So to begin with the methods are defined in the CSP file and now we want to port them over to a REST API.  Since it's a generated class I get nervous calling it like I am but I don't see another way.

Hi Michael,

This isn't a straight answer to the problem of extracting business logic from CSP pages - but if you haven't already, check out the project. Its an open source release of the framework we've been using to migrate our CSP and Zen apps to REST (Angular front end). 

If nothing else, it provides a uniform, safe and easy to maintain way of creating a REST API from an existing application. 

My process has generally been to copy CSP business logic to a class method in the relevant persistent class and expose it as a REST Action there (see Defining Actions in isc-rest user guide).  Its possible to expose any method in this way, so depending on your situation, it could make sense to point an action endpoint to the class methods in CSP directly, or use a wrapper method.

This recent presentation is a great place to start:

git hub: