What is the difference between IWS and CGI webservices?
Overview of Web Services on IBM i
In the IBM i operating system (grandson of the AS/400 and iSERIES machines), web services enable the exposure of native applications, such as RPGLE programs or SQL procedures, as APIs (typically REST or SOAP) to external clients.
Two primary native approaches are Integrated Web Services (IWS) and Common Gateway Interface (CGI). Both leverage the IBM i's HTTP server capabilities but differ in setup, flexibility, and handling of data.
What is IWS?
Integrated Web Services (IWS) is a built-in feature of IBM i that allows developers to quickly convert ILE-based programs (e.g., RPGLE service programs) or SQL statements into web services using a graphical wizard via the IBM i Access Client Solutions (ACS) or the HTTP Admin interface (e.g., at http://hostname:2001/HTTPAdmin).
IWS automatically handles serialization/deserialization of data into JSON or XML, mapping incoming request parameters directly to program parameters without requiring the developer to parse the full payload in code.
IWS runs on the Integrated Web Services Server, which is tightly integrated with the IBM i OS for security and management.
What is CGI?
Common Gateway Interface (CGI) is a standard protocol for executing external programs (e.g., RPGLE) from a web server in response to HTTP requests.
On IBM i, it uses the Apache HTTP Server instance, configured via the httpd.conf file (e.g., using ScriptAliasMatch directives to route URLs to programs). Unlike IWS, the entire request body (e.g., full JSON or XML) is passed as input to the program via environment variables or stdin, requiring the developer to handle parsing, processing, and output formatting manually in the code.
Pros and Cons
IWS Pros: Easier and faster to implement (less web services knowledge required); reuses tested business logic seamlessly; built-in security and OS integration.
IWS Cons: Restricted parameter support; less suitable for complex or custom request/response formats.
CGI Pros: Leverages existing RPG skills; greater control over the entire HTTP interaction; handles any data complexity.
CGI Cons: More setup effort and deeper web knowledge needed; potential for higher maintenance.
In practice, start with IWS for most scenarios due to its simplicity, and switch to CGI when, or if, IWS limitations arise (e.g., for non-standard payloads or advanced logging)
