· Jul 25, 2019 2m read

Forgery: A tool to mimick requests.

Hello everyone, it took some time but I'm finally getting things done again. Phew!
But for now, allow me to introduce a tool that I've been using frequently.

I call it Forgery.

This description has been taken from my GitHub repository, also available on OpenExchange:

Forgery is a server-side utility that allows executing simulated HTTP request by forging calls to REST applications. This makes Forgery ideal for using together with test suites that need to call the API via HTTP but could face issues with license usage and its grace period.

This works just like having a command-line agent that executes calls to your routes but without hitting the CSP Gateway, which means faster execution for unit tests and a easier way to debug the methods on your REST classes, all while keeping the same environment behavior from a normal HTTP request.

Just for a quick side-note: There's already a tool that follows this principle, and you can access it calling the $System.CSP.Shell(), however Forgery is much more configurable and aimed for developers using REST applications.

If you ever used the fetch API then you already know to how to use this tool:

set agent = ##class(Forgery.Agent).%New()
set sc = agent.Post({
  "url": "api/forgery/samples/echo",
  "headers": {
    "Content-Type": "application/json; charset=utf-8"
  "data": {
    "message": "Send me back"
.response, // This holds a stream of the response.
1, // Automatically outputs the response to the current device.

if $$$ISERR(sc) write "Received a server error: "_$System.Status.GetErrorText(sc)
return $$$OK

Also, Forgery is also 100% compatible with Frontier based applications.

Along with Post, you also have Get, Put, Patch, Head and Options, methods (although normally you would not use these ones).
Remember to read the README from my repository or the OpenExchange, especially the Troubleshooting section because there's some tips about working with cookies, sending files and more.

Discussion (0)1
Log in or sign up to continue