SlideShare a Scribd company logo
RPG & PHP REST Services
with Apigility
Chuk Shirley
Sabel Steel Service, Inc.
Club Seiden
Chuk Shirley
• Developing web applications
since 2007
• PHP since 2011
• Winner of the 2015 COMMON
Innovation Award for Sabel
Steel Service’s mobile web
application
@chukShirley
chukShirley@gmail.com
Today’s topics
• API concepts
• Apigility installation
• Server configuration
• Creating RESTful web services
• Sanitizing input
• Using the toolkit
• Error handling
• Testing
What is an API?
API Terminology
• 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”
API Terminology
• 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 DOMAIN DATA SOURCE
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
Domain
layer
Data source
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
• PHP Toolkit and XMLSERVICE Library
• REST Client (optional)
• Postman, cURL, etc.
Development Methods
• Local
• Apigility admin UI runs locally
• Edit your code locally
• Push changes to server
• Remote
• Apigility admin UI runs on server
• Edit your code locally (pull files from server first)
• Push changes to server
Download Skeleton App
• Start PASE shell
• Add PHP executable to PATH environment variable
PHP 5.6 and OpenSSL
• PHP 5.6 now verifies peer certificates by default
• Download “good known” CA bundle
• Change php.ini setting
Verify OpenSSL Version
• Only recent versions of OpenSSL can properly use this
CA bundle.
• Make sure you’re running at least 0.9.8
Too old!
Run Apigility Installer
• Rename the directory to AcmeAPI
• Return to PASE and change directories to /www
• Run the Apigility installer script
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 Apache Virtual Host	
• In /www/zendsvr6/conf/httpd.conf
• Template is on next slide
• You’ll need to supply three values:
• Server IP address (10.x.x.x, 192.x.x.x)
• 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>
Apigility Welcome Page
http://[server ip]:[port]/
Creating RESTful
web services
Initializing the DB2 Table
CREATE TABLE 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), 

NAME VARCHAR (50),

ADDRESS VARCHAR (75)

);
Designing the 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
Using the Admin Interface
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Project Structure
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Sanitizing Input
Adding Validation
Adding Validation
Add Filtering
Add Filtering
Using the toolkit
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 Toolkit Service
Apigility-Powered APIs on IBM i
Using the Toolkit
• Use CustomerResourceFactory to inject toolkit object
into CustomerResource
Using the Toolkit
• Edit CustomerResource::__construct() to require a
toolkit object and set the value of a class property
Using the Toolkit (PHP)
• Within each method reference the toolkit object with
$this->toolkit.
Using the Toolkit (CL)
Using the Toolkit (RPG)
Using the Toolkit (RPG)
Using the Toolkit (PHP)
Error handling
Error handling
• Use HTTP response status codes for errors
• Apigility supports API Problem format
• Uses application/problem+json mediatype
Sending the 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
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Apigility-Powered APIs on IBM i
Testing Your API
Additional Resources
• This presentation’s GitHub repo:

github.com/chukShirley/rpg-php-rest-services-apigility
• Apigility documentation:

www.apigility.org/documentation
• HTTP status codes cheat sheet:

http://httpstatus.es/
Questions?

More Related Content

PDF
Apigility-powered API's 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
PPT
Adobe Experience Manager - Replication deep dive
PDF
API Testing. Streamline your testing process.
Apigility-powered API's 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
Adobe Experience Manager - Replication deep dive
API Testing. Streamline your testing process.

What's hot (20)

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

Similar to Apigility-Powered APIs on IBM i (20)

PPTX
Basics Of Introduction to ASP.NET Core.pptx
PDF
Extending WordPress as a pro
PDF
Intro to CakePHP
PPTX
DEVNET-1128 Cisco Intercloud Fabric NB Api's for Business & Providers
PPTX
“ASP.NET Core. Features and architecture”
PDF
Node.js to the rescue
PPTX
PPSX
Advanced Web Development in PHP - Understanding REST API
PDF
Rest ful tools for lazy experts
PDF
RESTFul Tools For Lazy Experts - CFSummit 2016
PPTX
ASP.NET Mvc 4 web api
PPTX
ASP.NET vNext
PDF
API Economy, Realizing the Business Value of APIs
PPTX
MVC 6 - the new unified Web programming model
PDF
Web Services PHP Tutorial
PPTX
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
PDF
用Serverless技術快速開發line聊天機器人
PDF
Introduction to Infrastructure as Code & Automation / Introduction to Chef
PPTX
SOLID Programming with Portable Class Libraries
PPTX
Heading to the Cloud : Introduction to deploying a Provider-Hosted App in Azure
Basics Of Introduction to ASP.NET Core.pptx
Extending WordPress as a pro
Intro to CakePHP
DEVNET-1128 Cisco Intercloud Fabric NB Api's for Business & Providers
“ASP.NET Core. Features and architecture”
Node.js to the rescue
Advanced Web Development in PHP - Understanding REST API
Rest ful tools for lazy experts
RESTFul Tools For Lazy Experts - CFSummit 2016
ASP.NET Mvc 4 web api
ASP.NET vNext
API Economy, Realizing the Business Value of APIs
MVC 6 - the new unified Web programming model
Web Services PHP Tutorial
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
用Serverless技術快速開發line聊天機器人
Introduction to Infrastructure as Code & Automation / Introduction to Chef
SOLID Programming with Portable Class Libraries
Heading to the Cloud : Introduction to deploying a Provider-Hosted App in Azure
Ad

Recently uploaded (20)

PDF
top salesforce developer skills in 2025.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
ai tools demonstartion for schools and inter college
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
medical staffing services at VALiNTRY
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
history of c programming in notes for students .pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Online Work Permit System for Fast Permit Processing
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
top salesforce developer skills in 2025.pdf
PTS Company Brochure 2025 (1).pdf.......
Softaken Excel to vCard Converter Software.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Wondershare Filmora 15 Crack With Activation Key [2025
ai tools demonstartion for schools and inter college
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Understanding Forklifts - TECH EHS Solution
ISO 45001 Occupational Health and Safety Management System
medical staffing services at VALiNTRY
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
How to Migrate SBCGlobal Email to Yahoo Easily
history of c programming in notes for students .pptx
Transform Your Business with a Software ERP System
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Online Work Permit System for Fast Permit Processing
How to Choose the Right IT Partner for Your Business in Malaysia
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Upgrade and Innovation Strategies for SAP ERP Customers

Apigility-Powered APIs on IBM i