Building a Web UI and REST API w/Zowe Node.js SDK to Run TSO Commands
{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.
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:
- start a TSO address space
- send a command to a TSO address space
- receive a response from a TSO address space
- 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:
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
:
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.