Building a Web UI and REST API w/Zowe Node.js SDK to Run TSO Commands

Dan Kelosky
Zowe
Published in
4 min readOct 5, 2022

--

{Core}Here we’ll look at a skeleton project to build a web user interface (UI) and REST API using The Open Mainframe Project’s Zowe Node.js SDK. The UI is simple in that it enables the user to run TSO commands from a webpage:

Why

It doesn’t take a lot of code to do this, but it demonstrates one way that we can encapsulate or wrap complex operations in a shareable way, namely a web server. This allows us to host common logic in a server to be used by many users or services.

Logic in a server can be called from many clients

In other words, we can create logic to perform operations using z/OS jobs, data sets, TSO commands, and other mainframe services through a parameterized API which can be called from anywhere.

Tools

  • dotenv — configuration tool for our app
  • Express — used to quickly build REST APIs
  • Zowe Node.js SDK — makes calling mainframe infrastructure REST APIs easily
  • Bootstrap — web, front end framework
  • jQuery — more web tooling

We use dotenv to configure our project. It means that you can configure the project settings via a .env file in the root of the project containing as little info as:

HOST=localhost
PORT=3001
ZOSMF_HOST=some.mainframe.com
ZOSMF_PORT=443

The Zowe Node.js SDK makes calling mainframe REST APIs easier. For example, issuing a TSO command through the z/OSMF TSO REST API takes at least four distinct API calls. You must:

  1. start a TSO address space
  2. send a command to a TSO address space
  3. receive a response from a TSO address space
  4. end a TSO address space

Or, you can add the Zowe Node.js SDK to your project and call a single function to do the same operation:

Express lets you quickly spin up a REST service and/or host a UI. Here is a POST endpoint to call the function above, passing credentials supplied from the end user:

Line 13 obtains the authorization header from the callers to build a Session object on line 18. Then, on line 29, we invoke the z/OSMF REST API via the Zowe Node.js SDK.

Bootstrap is a UI framework to make responsive and mobile-friendly web applications.

jQuery is a JavaScript library to help with event handling when users interact with a web page.

Project

The complete project is here, but we’ll highlight some important parts below.

  • /web — folder contains HTML using Bootstrap
  • /src/render/view.ts — TypeScript code that will run in a web browser to call the Express-based API
  • /src/server/app.ts — the Express server

The Express server can run anywhere, it doesn’t need to be deployed to z/OS.

Running

After you clone, npm install, and npm run build the project. You configure it by creating a .env file and start it with npm run start:

You can access the web page at the address shown from startup or use the API via something like cURL:

Here we run a REXX program using our Express API

Try It Out!

Give the project a try and follow up here or within the repo if you get stuck along the way. With this base project, you can extend it to share higher level, custom build processes with your entire team!

If you enjoyed this blog, and would like to learn more about Zowe, check out more Zowe blogs here. You are also welcome to ask questions and join the conversation on the Open Mainframe Project Slack Channel #Zowe-dev, #Zowe-user or #Zowe-onboarding. If this is your first time using the Open Mainframe Project slack channel register here.

--

--

Dan Kelosky
Zowe

Likes programming/automation in mainframe (assembler, C/C++), distributed (Node.js), and web development (Firebase, Angular).