Apigility-powered API’s on IBM i
Chuk Shirley	

Sabel Steel Service	

Sure Consulting
Senior Software
Engineer
Subject Matter Expert
Founder and Owner
2015 Innovation Award
Winner
@ChukShirley chukShirley@gmail.com
TODAY’STOPICS
• API concepts	

• Apigility installation / Server configuration	

• Creating RESTful web services	

• Sanitizing input	

• Using the toolkit	

• Error handling	

• Tips
WHAT IS AN API?
APITERMINOLOGY
• Examples: 	

• IBM i OS commands (CRTLIB, DSPJOBLOG)	

• jQuery methods (jQuery.ajax(), jQuery.on())	

• RPG built-in functions (%DEC, %XLATE)
“An API is a way for two computer applications to talk
to each other over a network using a common
language that they both understand.”
Jacobson, Daniel and Greg Brail. Sebastopol, APIs:A Strategy Guide Sebastopol, CA: O’Reilly Media, Inc., 2012
• API = “Application Programming Interface”
APITERMINOLOGY
• API vs Web API	

• A Web API is an API accessed over HTTP	

• Web service vs Web API	

• A web service refers to one or many related API
functions	

• A web API is a collection of web services
APPLICATION LAYERS
Presentation Application & Domain Persistence
Web (HTML, CSS, JS) PHP Db2
Mobile (Objective C,
Cordova)
CL, RPG, COBOL, Java Sessions
Toaster app SQL Cache
Web API
LAYER COMMUNICATION
Presentation
layer
HTTP Request
HTTP Response
Application
/Domain
layers
Persistence
layer
DB
Interactions
Web API
APIGILITY INSTALLATION
REQUIREMENTS
• Code Editor (Zend Studio, RDi, Notepad, etc.)	

• Zend Server 6 or above running PHP 5.4.8 or above	

• PHPToolkit and XMLSERVICE Library	

• REST Client (optional)	

• Postman, cURL, etc.
DEVELOPMENT METHODS
• Apigility admin UI runs
locally	

• Edit your code locally	

• Push changes to server
Local Remote
• Apigility admin UI runs on
server	

• Edit your code locally (pull
files from server first)	

• Push changes to server
LOCAL: RUN PHP LOCALLY
• Download PHP to your local computer	

• Manual install	

• Homebrew,Vagrant, Macports	

• All in one (MAMP, XAMPP,WAMP, etc.)
LOCAL: RUN INSTALLATION
SCRIPT
php -r “readfile(‘https://apigility.org/install');” | php
*See Apigility docs for alternative installation methods
Install Apigility
Installation complete.
Running PHP internal web server.
Open your browser to http://localhost:8888, Ctrl-C to stop it.
cd /path/to/project/parent/directory
REMOTE INSTALLATION
DOWNLOAD SKELETON APP
• Add Zend Server’s binaries folder to PATH
environment variable
• Start PASE shell
VERIFY OPENSSLVERSION
• Only recent versions of OpenSSL can properly
use this CA bundle.	

• Make sure you’re running at least 0.9.8
Too old!
PHP 5.6 AND OPENSSL
• PHP 5.6 now verifies peer certificates by default	

• Download “good known” CA bundle
• Change php.ini setting
RUN APIGILITY INSTALLER
• Rename the directory to AcmeAPI
• Return to PASE and change directories to /www
• Run the Apigility installer script
php-cli -r “readfile(‘https://www.apigility.org/install');” | php-cli
SERVER CONFIGURATION
DISABLE OPCACHE
• Enable opcache blacklist in php.ini
• Create file opcache_blacklist.txt and add two
entries
DISABLE APC CACHE
• Change PHP setting in datacache.ini
• Set zend_datacache.apc_compatibility to “0”
CONFIGURE DIRECTORY
PERMISSIONS
• Make /config and /module directories
writable by web server
ADD APACHEVIRTUAL HOST	

• In /www/zendsvr6/conf/httpd.conf	

• Template is on next slide	

• You’ll need to supply three values:	

• Server IP address/DNS (10.x.x.x, 192.x.x.x, subdomain.domain.com)	

• Port number **Choose one that isn’t in use**	

• Path to the project	

• Restart Zend Server
Listen *:[port]
NameVirtualHost *:[port]
<VirtualHost *:[port]>
ServerName [server ip]:[port]
DocumentRoot "/www/AcmeAPI/public"
!
SetEnv APPLICATION_ENV "development"
AllowEncodedSlashes On
!
RewriteEngine on
<Location />
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
!
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
</Location>
</VirtualHost>
http://[server ip]:[port]/
CREATING RESTFUL 	

WEB SERVICES
INITIALIZINGTHE DB2TABLE
CREATETABLE MY_LIB.CUSTOMERS ( 

	

 ID BIGINT GENERATED ALWAYS AS IDENTITY 

	

 	

 (START WITH 1, INCREMENT BY 1, NO ORDER, 

	

 	

 NO CYCLE, NO MINVALUE, NO MAXVALUE, 

	

 	

 CACHE 20), 

	

 NAMEVARCHAR (50),

	

 ADDRESSVARCHAR (75)

);
DESIGNINGTHE URIS
HTTP Request
Method
Example URI Task
GET /customer Lists all rows
POST /customer Creates new row in db
GET /customer/{customer id} Fetch a particular row	

PUT /customer/{customer id} Update row in db
DELETE /customer/{customer id} Remove row from db
USINGTHE ADMIN INTERFACE
USINGTHETOOLKIT
ZF2 SERVICES
• The toolkit should be used as a service	

• Services are configured in the Service Manager	

• PHP array	

• Assembled at runtime from many locations	

• Global application services located at 

/config/autoload/application.config.php
ADDING DB2 SERVICE
ADDING DB2 SERVICE
ADDINGTOOLKIT SERVICE
PROJECT STRUCTURE
USINGTHETOOLKIT
USINGTHETOOLKIT
USINGTHETOOLKIT (PHP)
USINGTHETOOLKIT (CL)
USINGTHETOOLKIT (RPG)
USINGTHETOOLKIT (RPG)
USINGTHETOOLKIT (PHP)
ERROR HANDLING
ERROR HANDLING
• Use HTTP response status codes for errors	

• Apigility supports API Problem format	

• Uses application/problem+json mediatype
SENDINGTHE API PROBLEM
• You can produce an API Problem with one of two
methods:	

• return new ZFApiProblemApiProblemResponse()
• throw new Exception()
THROWING AN EXCEPTION
THROWING AN EXCEPTION
CUSTOMERRESOURCE::FETCH
()
Apigility-powered API's on IBM i
Apigility-powered API's on IBM i
ADDITIONAL RESOURCES
• This presentation’s GitHub repo:

http://github.com/chukShirley/rpg-php-rest-services-
apigility	

• Apigility documentation:

http://www.apigility.org/documentation	

• HTTP status codes cheat sheet:

http://httpstatus.es/
QUESTIONS?
BONUS!
TIPS
• Start with a small project	

• UseToolkit’s HTTP transport to run PHP locally
and RPG remotely	

• Abstract theToolkit calls
“BEST PRACTICE”
• Create ZF2 module to encapsulateToolkit	

• Composer package or php require()	

• MoveToolkit calls to domain (e.g., customer)
module	

• Use DTO instead of array
“BEST PRACTICE”
• Convert DTO to command/query object	

• Build command bus/query bus	

• Convert Service to command/query handler object	

• Restructure and rename command to reflect user’s
intent
REST AND USER INTENT
• REST is great for describing database actions (CRUD)
but usually not for representing user intent	

• Which HTTP method describes
Customer::payInvoice()?	

• The process of paying an invoice may include creating
db records, updating others, sending emails, and
interacting with another web API.
REST AND CQRS
• One solution: build your application as a set of
commands and queries(in the CQRS sense).	

• Treat each command/query as an endpoint and use
POST/GET http methods.	

• POST http://my.api.com/commands/CustomerPayInvoice	

• GET http://my.api.com/queries/FetchActiveCustomers
THANKS!

More Related Content

PDF
Apigility-Powered APIs on IBM i
PPTX
ADF Basics and Beyond - Alfresco Devcon 2018
PPTX
Building ColdFusion And AngularJS Applications
PDF
Bring api manager into your stack
PPTX
Flexible Permissions Management with ACL Templates
PPTX
Alfresco Process Services extension project - Alfresco DevCon 2018
PDF
API Testing. Streamline your testing process.
PPT
Adobe Experience Manager - Replication deep dive
Apigility-Powered APIs on IBM i
ADF Basics and Beyond - Alfresco Devcon 2018
Building ColdFusion And AngularJS Applications
Bring api manager into your stack
Flexible Permissions Management with ACL Templates
Alfresco Process Services extension project - Alfresco DevCon 2018
API Testing. Streamline your testing process.
Adobe Experience Manager - Replication deep dive

What's hot (20)

PPTX
They why behind php frameworks
PPTX
Let's play with adf 3.0
PPTX
Web API testing : A quick glance
PPTX
Testing soap UI
PDF
MidwestPHP 2016 - Adventures in Laravel 5
PPTX
Modular PHP Development using CodeIgniter Bonfire
PPTX
Practical Application of API-First in microservices development
PPTX
ASP.NET Core 1.0
PPTX
Introducing ASP.NET Core 2.0
PDF
Laravel - The PHP Framework for Web Artisans
PDF
O365Con18 - Implementing Automated UI Testing for SharePoint Solutions - Elio...
PDF
Laravel and CodeIgniter: pros & cons
PDF
ECS19 Elio Struyf - Setting Up Your SPFx CI/CD pipelines on Azure DevOps
PPTX
Process Orchestration with Flowable and Spring Boot
PDF
PHP, OAuth, Web Services and YQL
PDF
Hidden Gems in ColdFusion 2016
PDF
PPTX
AWS Meetup - Sydney - February
PDF
Sling Component Filters in CQ5
PPTX
A introduction to Laravel framework
They why behind php frameworks
Let's play with adf 3.0
Web API testing : A quick glance
Testing soap UI
MidwestPHP 2016 - Adventures in Laravel 5
Modular PHP Development using CodeIgniter Bonfire
Practical Application of API-First in microservices development
ASP.NET Core 1.0
Introducing ASP.NET Core 2.0
Laravel - The PHP Framework for Web Artisans
O365Con18 - Implementing Automated UI Testing for SharePoint Solutions - Elio...
Laravel and CodeIgniter: pros & cons
ECS19 Elio Struyf - Setting Up Your SPFx CI/CD pipelines on Azure DevOps
Process Orchestration with Flowable and Spring Boot
PHP, OAuth, Web Services and YQL
Hidden Gems in ColdFusion 2016
AWS Meetup - Sydney - February
Sling Component Filters in CQ5
A introduction to Laravel framework
Ad

Similar to Apigility-powered API's on IBM i (20)

PDF
Introduction to Apigility
PDF
Apigility introduction v2 (glasgow php)
PDF
Apigility – Lightning Fast API Development - OSSCamp 2014
PDF
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
PDF
API All the Things!
PDF
Easily extend your existing php app with an api
PDF
Build your APIs with apigility
PDF
Building APIs with Apigilty and Zend Framework 2
PPTX
Apigility & Restfull APIs
PDF
Php web app security (eng)
PPTX
Zend Products and PHP for IBMi
PDF
Professional PHP: an open-source alternative for enterprise development [Kort...
PDF
Using Zabbix API from Drupal
PPTX
Building and managing applications fast for IBM i
PDF
zingmepracticeforbuildingscalablewebsitewithphp
PDF
Zingme practice for building scalable website with PHP
PDF
Zingme practice for building scalable website with PHP
PDF
01 zingme practice for building scalable website with php
PDF
Better Bug Stomping with Zend Studio and Zend Server
PDF
An Express Guide ~ Zabbix for IT Monitoring
Introduction to Apigility
Apigility introduction v2 (glasgow php)
Apigility – Lightning Fast API Development - OSSCamp 2014
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
API All the Things!
Easily extend your existing php app with an api
Build your APIs with apigility
Building APIs with Apigilty and Zend Framework 2
Apigility & Restfull APIs
Php web app security (eng)
Zend Products and PHP for IBMi
Professional PHP: an open-source alternative for enterprise development [Kort...
Using Zabbix API from Drupal
Building and managing applications fast for IBM i
zingmepracticeforbuildingscalablewebsitewithphp
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHP
01 zingme practice for building scalable website with php
Better Bug Stomping with Zend Studio and Zend Server
An Express Guide ~ Zabbix for IT Monitoring
Ad

Recently uploaded (20)

PDF
Zenith AI: Advanced Artificial Intelligence
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PDF
Flame analysis and combustion estimation using large language and vision assi...
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
DOCX
search engine optimization ppt fir known well about this
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PPT
Geologic Time for studying geology for geologist
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
CloudStack 4.21: First Look Webinar slides
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
Modernising the Digital Integration Hub
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
Consumable AI The What, Why & How for Small Teams.pdf
Zenith AI: Advanced Artificial Intelligence
The influence of sentiment analysis in enhancing early warning system model f...
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Flame analysis and combustion estimation using large language and vision assi...
Custom Battery Pack Design Considerations for Performance and Safety
Final SEM Unit 1 for mit wpu at pune .pptx
search engine optimization ppt fir known well about this
Developing a website for English-speaking practice to English as a foreign la...
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
Convolutional neural network based encoder-decoder for efficient real-time ob...
Geologic Time for studying geology for geologist
Credit Without Borders: AI and Financial Inclusion in Bangladesh
CloudStack 4.21: First Look Webinar slides
Hindi spoken digit analysis for native and non-native speakers
A comparative study of natural language inference in Swahili using monolingua...
sustainability-14-14877-v2.pddhzftheheeeee
Modernising the Digital Integration Hub
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Consumable AI The What, Why & How for Small Teams.pdf

Apigility-powered API's on IBM i