Tips

Tips

The tips linked from this page are maintained in the Profound.js documentation and are written using Profound.js terminology, but each one applies to Profound API. Every example is built in a shared workspace named pjstips, and the examples assume an instance running at localhost:8081 - substitute your own host and port where needed.

Overview

This page indexes the worked examples in the PJS Tips series that apply to Profound API. Each entry describes what the tip demonstrates and when it is worth following, so you can tell whether it is the one you need before you open it.

Unlike the reference pages elsewhere in this section, these tips are complete walkthroughs. Each one builds a working file, with the full source included, that you can run and then adapt.

Start with Tip 1. It creates the pjstips workspace that every other tip saves its files into, and several tips call a service that was built in an earlier tip. Working through them in order is the most reliable path.

Tips That Apply to Profound API

Tip

What It Demonstrates

Use It When

Tip

What It Demonstrates

Use It When

Tip 1: Create a workspace

Creating the pjstips workspace in the IDE, bookmarking the workspace URL, and the host and port convention that every following tip uses.

Always, first - the remaining tips save their files into this workspace.

Tip 2: Call, test, and debug a module as a web service

Marking a .js file as an Express Route with an HTTP method and route path, calling it from a browser at /run/<route path>, and passing values in as query string parameters.

You want to exercise a module's logic in a browser without building an API route around it first. Tips 3 through 6 call services created here.

Tip 3: Call a low-code module from an RPG program

Building a low-code module that uses the Consume REST Service plugin to POST to a service, then calling that module from RPG using the code generated on the IBM i Call Interface panel and the PJSCALL program.

You are exposing low-code logic to existing RPG programs, or bridging an RPG program to an outside REST service.

Tip 4: Debug low-code by converting it to code

Diagnosing a deliberately broken low-code module by converting it to the Profound.js code the low-code steps generate, which also shows what a given plugin does behind the scenes.

The Designer debugger has not narrowed a problem down, or you want to see what a plugin actually generates.

Tip 5: Map a whole body and whole response at once

Filling an entire request body from an input parameter object and reading an entire response into an output parameter object in the Consume REST Service plugin, by matching your parameter structures to the service's JSON instead of assigning field by field.

Your parameter structure already matches the service contract and you want to avoid a long run of field assignment steps.

Tip 6: Handle variable-size arrays with RPG

Sending only the populated elements of a fixed-size RPG array to a REST service, and reporting back how many elements the service returned, using a separate element count parameter.

An RPG program passes or receives an array whose actual length varies at run time, which RPG cannot express directly.

Tip 8: Return multiple records from an RPG program

Calling an RPG program that returns a data structure array plus an element count from a Profound API route, then using a Write Custom Node.js Code step to trim the unused elements so the route outputs only the records that were actually populated.

A Profound API route returns a multi-record result set that is sourced from an RPG program.

Tips Specific to Profound.js

One tip in the series covers Profound.js application development rather than APIs, and is not listed above:

  • Tip 7 - Uses the PJSMYIP and PJSCALL commands to call a "regular" (not low-code) Profound.js module running on a PC from an IBM i green screen. This is a development workflow convenience rather than an API topic.

The load-all subfile walkthrough that was previously Tip 8 has been merged into Generating Profound.js Modules with JumpStart.

For the complete series, see PJS tips.


Related Pages