Question
· Feb 21

How To Test REST API Methods without referring to a Web Server?

Hi folks!

I'm building a very simple REST API.

But before testing it via a Web Server what I want to make sure that REST API methods work in principle.

Is it an easy way to "fake" the web-server request and get a result e.g. of the method with signature like that?

ClassMethod GetAllRecords(pRequest As %CSP.Request, pResponse As %CSP.Response) As %Status

e.g. calling it in Terminal?

Product version: IRIS 2024.3
Discussion (6)5
Log in or sign up to continue

I don't see why you can't create another ClassMethod to test GetAllRecords()

Your test ClassMethod would need to create instances of %CSP.Request and %CSP.Response and set any properties required but it should be possible.

Looking at the Documentation for %CSP.Request it actually mentions the Command Line:

http://cg-az-cendev01/csp/documatic/%25CSP.Documatic.cls

property CSPGatewayRequest as %Boolean [ InitialExpression = 0 ];

True if the request came the CSP Gateway, and false if it was from the command line or the built in web server.

If it's a simple get request, you can test from the terminal without setting up a %Net.HttpRequest. I usually do it like this, in a terminal (for more complicated ones with a request body, you have to initialize %request to a %CSP.Request and set it up too):

set %response = ##class(%CSP.Response).%New()
do ##class(Your.Class).YourMethod(yourarguments)
zw %response