Leveraging IBM i and RPG for Web Servicing
By Mihael Schmidt / April 4, 2022
Why IBM i and RPG offer key strengths for web servicing, and a look at other programming languages and frameworks
The web service in question is about providing the shipping addresses of customers, nothing special. The data is stored in a table on the IBM i server.
Some of the technical requirements were:
- Hosted on-site (as it is only locally used)
- Support access Db2 on IBM i
- JWT support
- Produce JSON
- Support OPTIONS HTTP requests
- REST like request path
- OpenAPI compatible web service
Choosing RPG and IBM iThe requirements didn't specify a programming language or a platform where the service needs to run. The programming languages I could choose from included Java, TypeScript and RPG.
I decided that out of all of the options listed above, RPG was the perfect fit for this web service.
Some of the benefits of RPG included:
- Always available database connection, with no hassle in database connection pools or configurations
- Native battle tested HTTP server framework: ILEastic
- Fast and feature-rich JSON library: noxDB
- A very small number of dependencies (four other software libraries)
- No extra tooling necessary
- Good response times (< 20ms for this particular web service)
- Extremely small memory footprint (< 10 MB)
- No extra training or tooling for deployment and maintenance
As most applications are backed by a database, the integrated Db2 on IBM i is a perfect match for our web service. Coupled with the native programming language RPG, it gives you a super fast database access as database functions are first-class citizens in RPG.
RPG: A Minimal Number of DependenciesOne thing I like most about RPG is that you have a very small and manageable amount of dependencies with no extra tooling needed. Let’s take a look at the numbers:
RPG: Four dependencies
Java: > 40 dependencies (Helidon, Quarkus)
TypeScript: > 400 dependencies (Express)
Note: These numbers reflect my typical setup for a web service with database access.
You might be saying, “I can get away with fewer dependencies with a different framework!” Yes, perhaps you can. However, those numbers are from projects which use the basic features of those frameworks, reflecting my typical setup for a web service project with database access. The aim was simplicity. With less features and much more effort you probably can get those dependencies down. But simplicity results in less development time and will save you a lot of stress.In my opinion RPG wins this, hands down!
No Extra Training or Tooling in RPG
The web service program written in RPG is another ILE program. There’s nothing special about it, no magic or special treatment needed. Simply start it like any other normal ILE program and include it into your workload on the IBM i server as you normally would with programs. You can manage and monitor it as any other program on the IBM i server—making it so much easier to hand it over from development to DevOps.
From Dev to DevOpsA smooth transition to the DevOps and the communication with the web service are equally important.
ILEastic supports everything we need to create a pretty web API. It is easy to create an OpenAPI document which matches the web service. There are several free and available tools out there for designing such documents. Some of them include:
Providing an OpenAPI document made the job for the consumer much easier, it shows that your web service is very likely compatible with the rest of the world.
There is nothing distinct about a web service written in RPG with ILEastic, and that’s a good thing. It has a similar feel to other web services. The consumer doesn't have to learn anything new in order to use this web service as it is cohesive with the rest of the applications and web services.
ILEastic and noxDB Development"Nothing special" also applies to the development with ILEastic, in the best possible way. ILEastic is provided as a service program and a copybook. Simply include the copybook into your source and bind your program object to the service program. You can build your web service program object with every tool out there. It integrates perfectly into any existing environment (i.e., Change Management Systems), but it also works well with tools like Make or Bob.
ILEastic's API is well-written, feature-rich and fully documented. It also supports HTTP methods which are not commonly used (depending on how deep you are into this topic) such as HEAD, OPTIONS or PATCH. The plugin system allows you to handle generic tasks like authentication or CORS at a single point and plug it into your setup.
Another positive about using ILEastic is that it lets you use whatever you want for content creation. This is where noxDB comes into play, an ILE service program that lets you parse and generate JSON and XML. It also has an SQL interface so you can directly generate JSON from SQL. With noxDB you have full control over your JSON output. You can start your development with designing your web API with your favorite OpenAPI editor and then implement it with ILEastic and noxDB. The combination of ILEastic and noxDB is like peanut butter and jelly. There is nothing better!
Congruent ConceptsWhat is even better is that you don't need to learn anything conceptually new when you are coming from the Java or Node.js world. It works the same: configure the embedded server, write the end point functions, configure the routes to your functions and, last but not least, start the server. With the exception of all the advantages you get with the ILE environment and having Db2 on IBM i, you will already know what to expect.
Web Services and More on ILEasticI hope this article answered all your questions. Grab your peanut butter and jelly and start cooking some great web services on IBM i. Enjoy!
If you’re looking for more technical details about ILEastic you can find a tutorial here.
Both projects—ILEastic and noxDB—are open source and come with several examples which you can find in their code repositories.
Happy web servicing!
AIX / IBM i / Linux on POWER / Article / Application development / IT infrastructure / RPG
About the author
Mihael Schmidt is a software developer at Bauformat Küchen GmbH & Co. KG with over 20 years of experience in RPG and Java.
See more by Mihael Schmidt