SlideShare ist ein Scribd-Unternehmen logo
1 von 60
Downloaden Sie, um offline zu lesen
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
()
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!

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

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

Ähnlich wie Apigility-powered API's on IBM i

REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptx
Jason452803
 

Ähnlich wie Apigility-powered API's on IBM i (20)

Intro to CakePHP
Intro to CakePHPIntro to CakePHP
Intro to CakePHP
 
Introduction to Apigility
Introduction to ApigilityIntroduction to Apigility
Introduction to Apigility
 
Node.js to the rescue
Node.js to the rescueNode.js to the rescue
Node.js to the rescue
 
Extending WordPress as a pro
Extending WordPress as a proExtending WordPress as a pro
Extending WordPress as a pro
 
Apigility introduction v2 (glasgow php)
Apigility introduction v2 (glasgow php)Apigility introduction v2 (glasgow php)
Apigility introduction v2 (glasgow php)
 
Continuous API Strategies for Integrated Platforms
 Continuous API Strategies for Integrated Platforms Continuous API Strategies for Integrated Platforms
Continuous API Strategies for Integrated Platforms
 
Deploy and Access WebSphere Liberty and StrongLoop REST Endpoints on IBM Bluemix
Deploy and Access WebSphere Liberty and StrongLoop REST Endpoints on IBM BluemixDeploy and Access WebSphere Liberty and StrongLoop REST Endpoints on IBM Bluemix
Deploy and Access WebSphere Liberty and StrongLoop REST Endpoints on IBM Bluemix
 
REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptx
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
Getting Started with API Management – Why It's Needed On-prem and in the Cloud
Getting Started with API Management – Why It's Needed On-prem and in the CloudGetting Started with API Management – Why It's Needed On-prem and in the Cloud
Getting Started with API Management – Why It's Needed On-prem and in the Cloud
 
“ASP.NET Core. Features and architecture”
“ASP.NET Core. Features and architecture” “ASP.NET Core. Features and architecture”
“ASP.NET Core. Features and architecture”
 
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
Building production-quality apps with Node.js
Building production-quality apps with Node.jsBuilding production-quality apps with Node.js
Building production-quality apps with Node.js
 
Apic dc api deep dive
Apic dc api deep dive Apic dc api deep dive
Apic dc api deep dive
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
 
DEVNET-1128 Cisco Intercloud Fabric NB Api's for Business & Providers
DEVNET-1128	Cisco Intercloud Fabric NB Api's for Business & ProvidersDEVNET-1128	Cisco Intercloud Fabric NB Api's for Business & Providers
DEVNET-1128 Cisco Intercloud Fabric NB Api's for Business & Providers
 
ITB2017 - Keynote
ITB2017 - KeynoteITB2017 - Keynote
ITB2017 - Keynote
 
Heading to the Cloud : Introduction to deploying a Provider-Hosted App in Azure
Heading to the Cloud : Introduction to deploying a Provider-Hosted App in AzureHeading to the Cloud : Introduction to deploying a Provider-Hosted App in Azure
Heading to the Cloud : Introduction to deploying a Provider-Hosted App in Azure
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Apigility-powered API's on IBM i