LoopBack on IBM i

loopback-connector-db2ibmi is still pre-pre-alpha. Use with caution.

Installing LoopBack

This uses loopback-cli in order to create a LoopBack Project. That is thelb command seen below. A list ofloopback-cli commands can be found here.

The commands above in order are simply:

$ lb # Follow configuration instructions. Above I choose default for each.
$ npm install loopback-connector-db2ibmi --save

This will give us everything we need to begin making an API. To start with, let’s define our data source.

Defining a Data Source

At the moment, a data source will need to be created for each library. So, in this case, think of a data source as a library, or schema, in the database. Let’s first create the data source vialb datasource, and then we’ll edit the contents ofdatasource.js once it the source has been generated.

All that needs to happen for now is to add a schema to the data source:

Now that we have a data source, we can create models to our heart’s content, and they’ll have CRUD + Querying out of the box.

Defining Models

Below is me defining a model vialb model and filling out the configuration to matchECOMMERCE_USERS , which I made in my Apigility Entity Mapper Tips article. Tables, columns, etc. are all case sensitive. This is why you see me yelling all my properties and such.

Don’t forget to define which column is the identity column. This is defined withinproject-dir/common/models/ecommerce_users.json.

That’s it! Now we have a nifty API out of the box to manipulate our data we just defined with a model. Just start the server withnode ., and go to the address in your browser to explore your API. Make sure to define the correct port in theproject-dir/server/config.json. For example, the port I had to use for my Litmis Space was63433.

Below is me exploring the API athttp://spaces.litmis.com:63433/explorer. I didn’t do anything other than what I did above for these requests to work.

loopback-connector-db2ibmi Github

Contributions are more than welcome over at the loopback-connector-db2ibmi Github as it is very much in the beginning stages.

Leave a Reply

Your email address will not be published. Required fields are marked *