Question
· Aug 11, 2023

OnPre/Before/After Method in %CSP.REST for Common Code?

I have tried many methods from super classes of %CSP.REST but I can't find a method I can override that will run after the %response object is created so I can set a header that is common to each implementation method.  It's one line of code in each method to set the header but it would like to make it super easy, simple and just have a method that runs on, before, after the implementation method to set this common header (we want to return the API version in each responses HTTP headers.

Any ideas?  I know I tried OnPreHTTP, OnPage and a few others, but those all seem to be related to the %request; I need to catch a method to handle the %response.

Discussion (2)2
Log in or sign up to continue

Hello @Michael Davidovich ,

Did you try to override OnPreDispatch ?

Also you can configure your web application to use a subclass of %CSP.SessionEvents and override OnStartRequest, OnEndRequest .

Set Application = "/csp/YourWebApp"
Do ##class(Security.Applications).Get(Application, .p)
Set p("EventClass") = "YourCSPEventsClassName"
Set sc = ##class(Security.Applications).Modify(Application, .p)