IBM i CGI Webservices

About IBM i CGI Webservices

CGI webservices on IBM i are a classic yet powerful way to expose business logic and data to the web using the Common Gateway Interface (CGI). They’re like the OG method for turning RPG or CL programs into web-accessible endpoints before REST APIs and open-source frameworks stole the spotlight.

What Are CGI Webservices?

CGI (Common Gateway Interface) is a standard protocol that allows web servers to execute external programs like RPGLE or CLLE and return the output to the client (usually a browser or another system).

On IBM i, CGI webservices typically:

  • Run RPG or CL programs triggered by HTTP requests
  • Use environment variables to receive input (like query strings or POST data)
  • Output HTML, JSON, or plain text back to the client

How They Work on IBM i

Web Server Setup IBM i uses the Integrated Web Server (IWS) or Apache HTTP Server to host CGI programs.

Program Invocation When a request hits a CGI endpoint, the server launches the RPG or CL program associated with that URL.

Input Handling Input parameters are passed via environment variables or stdin. You can parse them using RPG or CL logic.

Output Generation The program writes output to stdout this becomes the HTTP response. You can format it as HTML, JSON, or XML.

Why do we like them?

We appreciate CGI web services for three main reasons: exposing legacy RPG logic to modern web applications, creating lightweight APIs for internal tools, and integrating IBM i with external systems through HTTP.

Module Content

CGI webservices on IBM i are a classic yet powerful way to expose business logic and data to the web using the Common Gateway Interface (CGI). They’re like the OG method for turning RPG or CL programs into web-accessible endpoints before REST APIs and open-source frameworks stole the spotlight.

What CGI Is in IBM-i Context

MEMBERS ONLY

CGI (Common Gateway Interface) refers to the method by which RPGLE programs interact with HTTP requests/responses via the IBM i HTTP server.

YAJL for IBM i

MEMBERS ONLY

YAJL (Yet Another JSON Library) for IBM i is a JSON parsing and generation library designed to work with the IBM i platform. It provides a way to handle JSON data in RPG (Report Program Generator) and other programming environments on IBM i.

YAJL (Yet Another JSON Library) is a JSON parsing and generation library that can be used in RPG and other programming languages on the IBM i platform. Here’s a step-by-step guide on how to download and install YAJL on your IBM i system:

Aimed at RPG developers familiar with IBM i, this lesson serves as both a tutorial and an inspiration, demonstrating how traditional RPG skills can be adapted to modern web service needs using YAJL. It concludes by encouraging readers to explore the open-source YAJL library and experiment with their own JSON-based web services.

Now we know that YAJL (Yet Another JSON Library) for IBM i is a JSON parsing and generation library - lets look at some simple examples of how to use YAJL in RPG to parse a JSON string and generate a JSON string. This example assumes you have YAJL installed and configured on your IBM i system.

Building Webservices with JSON (YAJL)

MEMBERS ONLY

Come with me while we stroll through the process of creating an IBM i HTTP Server with IBM Web Administration for i. This IBM's browser based webserver creation application.

To configure the IBM i HTTP Server for YAJL (Yet Another JSON Library), you can create with the default WEB UI or you can do it all from the command line. Also known as - the good old green screen. 1. Install YAJL: - Download YAJL from Scott Klement's repository. 2. Create and Configure HTTP Server Instance: - If you don't have an existing HTTP server instance, create one. 3. Set Up Web Services: - Use RPGLE to create web services that handle JSON data. 4. Configure HTTP Server for JSON Handling: - Ensure your HTTP server is configured to handle JSON requests. This involves setting up the appropriate directives in your HTTP server configuration files to route requests to your RPG programs that use YAJL. 5. Test Your Configuration: - After setting up, test your configuration by sending JSON requests to your server and verifying the responses. Debugging tools and logs can be very helpful during this step.

To configure the IBM i HTTP Server for YAJL (Yet Another JSON Library), you'll need to add just a few lines of code! 1. Install YAJL: - Download YAJL from Scott Klement's repository. 2. Create and Configure HTTP Server Instance: - If you don't have an existing HTTP server instance, create one. 3. Set Up Web Services: - Use RPGLE to create web services that handle JSON data. 4. Configure HTTP Server for JSON Handling: - Ensure your HTTP server is configured to handle JSON requests. This involves setting up the appropriate directives in your HTTP server configuration files to route requests to your RPG programs that use YAJL. 5. Test Your Configuration: - After setting up, test your configuration by sending JSON requests to your server and verifying the responses. Debugging tools and logs can be very helpful during this step.

Time to secure our IBM i HTTP Webserver and keep our webservices, and more importantly, our DATA safe and secure.

Some simple SQLRPGLE code that will run as an IBM i webservice... this webservice will run on the IBM i Integrated Web Server, designed to receive an internet JSON payload and save it to an IFS location.

This reads the JSON from the IFS – decodes it using Y.A.J.L and reports on time taken to perform decode. Writing an RPG program to read JSON using YAJL is actually pretty straightforward — I hope this code example helps!

Postman is a good choice for testing web services for several reasons: Ease of use: Postman provides a user-friendly interface that makes it easy to create, send, and manage HTTP requests. This allows developers and testers to quickly set up and execute tests without having to write complex code. Comprehensive features: Postman offers a wide range of features for web service testing, including support for different HTTP methods (GET, POST, PUT, DELETE, etc.), headers, query parameters, request bodies, and authentication mechanisms. It also provides features for creating test scripts, generating code snippets, and managing collections of requests. Collaboration and sharing: Postman allows users to share their requests, test suites, and environments with team members, enabling collaboration and streamlining the testing process. Debugging and troubleshooting: Postman provides detailed information about the requests and responses, including headers, status codes, and response bodies. This makes it easier to identify and debug issues with the web service. Automation and integration: Postman can be integrated with various tools and platforms, such as CI/CD pipelines, to automate the testing process and ensure consistent and reliable testing across different environments. Cross-platform compatibility: Postman is available for multiple platforms, including Windows, macOS, and Linux, making it accessible to developers and testers working on different operating systems. Overall, Postman's combination of ease of use, comprehensive features, collaboration capabilities, and integration options make it a popular and effective choice for testing web services.

Building Webservices with Native IBM i SQL

MEMBERS ONLY

This reads the JSON from the IFS – decodes it using JSON_TABLE and reports on time taken to perform decode.

Building Webservices with JavaScript - iTOOLKITJS

MEMBERS ONLY

itoolkit (itookitjs) is not an alternative to Node.js, it is the essential IBM i integration library that runs inside Node.js For building a web server as a modern replacement for 5250 green screens, the practical combination used by most IBM i shops in 2026 is: Node.js + Express (or Fastify) + itoolkit In this lesson we will look at all the components and build a sample Web UI Version of a classic 5250 File Update program.

NPM is a software registry, package manager and installer for Node.js and other code packages. On IBM i, NPM is exactly the same beast you know from the Linux / Windows world… just running inside the IBM-i PASE environment. NPM stands for Node Package Manager. It is: A package manager for Node.js A tool used to install, update and manage JavaScript libraries Basically the “yum / apt / RPM” of the Node.js ecosystem If you’re writing Node.js on IBM i, you’ll use NPM constantly. How does it work on the IBM i System?

You maintain legacy RPG code and want to connect it to web apps. This series shows you how. Use RPGLE for business logic like create and update operations. In Part 2, add JavaScript endpoints with itoolkitjs. This part covers the IBM i setup. Create physical files for data. Build an RPGLE program for basic CRUD. You end with a callable module for APIs. You need RPGLE basics. No web service experience required. Prerequisites Access to IBM i with SEU, RDi, or ACS. Knowledge of physical files and free-format RPGLE. A test library like MYLIB.

Secure the IBM i file by combining object-level authorities, a dedicated service user, transport-layer protection, least-privilege SQL access, encryption at rest, and comprehensive auditing; implement network-level controls and service-side validation to ensure only authorized webservices can read and serve the data

This program teaches the fundamentals of building RESTful webservices in modern RPGLE. You'll learn how to create a backend API that handles all four CRUD operations (Create, Read, Update, Delete) on a database file. The program demonstrates proper parameter handling, database validation, error management, and status messaging - essential skills for building robust webservices that can be consumed by web applications, mobile apps, or other systems. By studying this code, you'll understand how to structure a webservice program, validate input data, perform database operations safely, and return meaningful status messages to the calling application.

Here's the IBM i webserver stack, colour-coded. We have already covered this but this a simple reference card to view if, probably when, you get confused.

This lesson shows how to wrap existing RPGLE programs as HTTP endpoints using Node.js, the iToolKit (itoolkitjs), and Express. You will learn how to call RPGLE services from JavaScript, map parameters and results, handle errors and transactions, and deploy a simple secure endpoint ready for testing with Postman or a frontend app. Expect pragmatic examples, a working Node app, and a few light jabs at excessive green-screen nostalgia.

This lesson shows how to build a lightweight JavaScript wrapper that exposes existing RPGLE service programs as HTTP-friendly endpoints. You will learn to marshal parameters, invoke RPG programs safely from Node.js, normalize return structures, handle errors and transactions, and return clean JSON responses suitable for frontend apps and API consumers.

Picture this: your battle-hardened RPGLE program, that trusty beast churning out invoices, crunching payroll, or spitting out stock reports suddenly gets a glow-up. No more hiding behind the firewall; it's out there in the wild, sipping HTTP requests like a pro and firing back JSON payloads faster than you can say "STRTCPSVR". Let's dive into deploying our HTTP Web Server

Testing webservices? There are so many techniques and tools out there! Let's look at my favorite ways of testing IBM i Webservices.

Ready to learn?
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>