Written by

Senior Startups and Community Programs Manager at InterSystems Corporation
Question Evgeny Shvarov · 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

Comments

Enrico Parisi · Feb 21

To my knowledge what can be done it's making a call via Web Gateway using %Net.HttpRequest.

I'm afraid that without going trough the Web Gateway it's not possible, but I'd love to be proven wrong.

0
Oliver Thompson · Feb 21

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.

0
Robert Cemper · Feb 21

Never tried it for long time , but $system.CSP.Shell() might be a starting point
$system.CSP.*  seems to have some more useful methods.

0
Chris Stewart · Feb 21

Yes, if you set up a response and request programatically as Oliver Thompson said, then you can just call the ClassMethods rather than going through HTTP to Rest.   

0
David Hockenbroch · Feb 21

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
0