Skip to Main Content
InterSystems Ideas
We love hearing from our users. Tell us what you want to see next and upvote ideas from the community.
* Bugs and troubleshooting should as usual go through InterSystems support.

Allow overriding of the class method call for routing within %CSP.REST.DispatchRequest

I would like the process of calling the destination class method within the DispatchRequest method of the %CSP.REST class to be an overridable method.

Currently, I am manually creating REST APIs using ObjectScript. When there are cross-cutting concerns that I want to handle in all the class methods mapped by UrlMap (such as common exception handling with try-catch, logging, etc.), I have to write boilerplate code in all the class methods. (Although there is an OnPreDispatch method, this method cannot control exceptions that occur in the class methods mapped by UrlMap with common exception handling.)

As a specific proposal, could the following code in the DispatchRequest method within the %CSP.REST class, which calls the final destination class method, be changed as follows? (Or add an overridable callback method equivalent to the following.)

Before change:

Within the %CSP.REST DispatchRequest method:

#; Dispatch
Set tSC=$classmethod(tClass,tTarget,pArgs...)

After change:

Within the %CSP.REST class:

/// Define a new method in %CSP.REST
ClassMethod InvokeRestMethod(tClass As %String, tTarget As %String, pArgs... As %String) As %Status
{
return $classmethod(tClass,tTarget,pArgs...)
}

Within the DispatchRequest method:

#; Dispatch
Set tSC=..InvokeRestMethod(tClass,tTarget,pArgs...)
#; Old
#; Set tSC=$classmethod(tClass,tTarget,pArgs...)

Users can define a derived class as follows and inherit it in all REST classes where they want to perform common processing, allowing them to manage boilerplate code for cases such as exception handling in a single class method.

/// Override in a class that inherits from %CSP.REST
ClassMethod InvokeRestMethod(tClass As %String, tTarget As %String, pArgs... As %String) As %Status
{       
set status = $$$OK
try {
tstart
set status = ##super(tClass, tTarget, pArgs...)
if ($$$ISERR(status)) {
trollback
} else {
tcommit
}
} catch ex {
trollback
set status=ex.AsStatus()
}
return status
}

By adding such a method, users who manually create REST APIs can have a better development experience. Is it possible to implement this idea or a similar feature?

  • ADMIN RESPONSE
    Feb 27, 2025

    Thank you for submitting the idea. The status has been changed to "Needs review".

    Stay tuned!