Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Architeching a php application with interfaces to the ib mi

224 views

Published on

In this session we’ll walk through a case study of developing a PHP application using an API to interface with IBM i data. This is a great example of how IBM i developers can leverage their knowledge of business rules and authorization to help speed up the development of PHP applications.

Published in: Internet
  • Be the first to comment

  • Be the first to like this

Architeching a php application with interfaces to the ib mi

  1. 1. Architecting a PHP Application with Interfaces to IBM i Presented by: Chelsea Fenton Senior Web Application Developer Fresche Solutions October 2017
  2. 2. 2Fresche Solutions | BCD - looksoftware - Quadrant Case Study ■ In this session we’ll walk through a case study of developing a PHP application using web services to interface with IBM i data. This is a great example of how IBM i developers can leverage their knowledge of business rules and authorization to help speed up the development of PHP applications. ■ You’ll learn how ZF3, RPG, and Bootstrap were used to develop an application that: ▶ Separates the front end coding from the backend ▶ Optimizes the skills of IBM i and web developers ▶ Works on both desktop and mobile devices ▶ Integrates with other systems
  3. 3. 3Fresche Solutions | BCD - looksoftware - Quadrant Who/What/Why ■ Who? ▶ Truck Parts Distributor ■ What? ▶ Needed a single place for dealers to access all their information ■ Why? ▶ Their customer service representatives were spending too much time on the phone with dealers looking up basic transactional information ▶ They had 5+ different sites the dealers could use already
  4. 4. 4Fresche Solutions | BCD - looksoftware - Quadrant Wish List ■ Responsive ■ Metro Tile Look and Feel ■ Single dashboard for all their dealer sites ■ Customizable by RPG staff ■ Ability to easily add more components in the future
  5. 5. 5Fresche Solutions | BCD - looksoftware - Quadrant Concept
  6. 6. 6Fresche Solutions | BCD - looksoftware - Quadrant Discoveries ■ Permissions / Authority model was complex and built deep into existing RPG programs and modules
  7. 7. 7Fresche Solutions | BCD - looksoftware - Quadrant Discoveries ■ Their in house IT were great with RPG ■ Not so great with PHP ■ They needed to maintain business rules through existing RPG ■ We didn’t want to duplicate any business logic
  8. 8. 8Fresche Solutions | BCD - looksoftware - Quadrant Answer? Web Services!!!!!
  9. 9. 9Fresche Solutions | BCD - looksoftware - Quadrant Concept ■ Since the client wanted full control over the data presented on the site, we went with web services ■ The front end was built with PHP, Zend Framework 3 and Bootstrap ■ The back end web services were built by their internal RPG staff ■ The PHP does not interact directly with any of the existing data
  10. 10. 10Fresche Solutions | BCD - looksoftware - Quadrant Application Flow
  11. 11. 11Fresche Solutions | BCD - looksoftware - Quadrant RESTful Web Service - RPG ■ For this project we used RESTful web services hosted on the IBM i , written in RPG ■ The PHP application makes a request to a URI running on the IBM i and reads the JSON response sent back
  12. 12. 12Fresche Solutions | BCD - looksoftware - Quadrant Example - Menu Authority Web Service Request http://host:port/web/services/LoadDlrMenuFlg/UserID Web Service Response { "ERRORMSG": "", "USERNAME": "Test User", "COMPONENTS": [ "PRICE_INQ", "ORDER_INQ" ] }
  13. 13. 13Fresche Solutions | BCD - looksoftware - Quadrant Web Service Server - IBM i ■ http://hostname:2001/HTTPAdmin https://www.ibm.com/developerworks/ibmi/library/i-rest-web-services-server1/
  14. 14. 14Fresche Solutions | BCD - looksoftware - Quadrant Web Service Server - IBM i
  15. 15. 15Fresche Solutions | BCD - looksoftware - Quadrant Web Service Server - IBM i
  16. 16. 16Fresche Solutions | BCD - looksoftware - Quadrant RPG Web Services ■ Under the covers the web services were just RPG programs. ■ Their current developers could write and maintain them ■ They could continue to use the same security routines that their other applications used ■ Bonus - It doesn’t matter to the website how these are implemented
  17. 17. 17Fresche Solutions | BCD - looksoftware - Quadrant Web Service Security ■ Understandably they did not want these web services available to the world at large ■ No Problem! ■ Web service server was made available to the IBM i only, meaning only calls from the IBM i itself could access them ■ Our PHP application would interact directly with the web services
  18. 18. 18Fresche Solutions | BCD - looksoftware - Quadrant Web Service Security class DataService { ... public function executeJsonRequest($serviceUrl) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $serviceUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // basic auth with service account curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $userId . ':' . $password); // execute request $response = curl_exec($ch); curl_close($ch); // if the request was successful if ($response) { // attempt to convert to json $jsonResponse = json_decode($response, true); } } ... }
  19. 19. 19Fresche Solutions | BCD - looksoftware - Quadrant Web Service Caching ■ The client was concerned about the load they would see on their IBMi from the web service calls ■ For data which wasn’t likely to change often we decided to cache it ▶ to speed up performance ▶ to limit the demand on the IBM i ■ Drop List values for example
  20. 20. 20Fresche Solutions | BCD - looksoftware - Quadrant Web Service Caching class DataService { ... public function __construct() { $this->dataCache = new Container('apiData'); } public function fetchJsonData($serviceName, $userName) { $cacheName = $serviceName . $userName; // look for data in session cache $data = $this->dataCache->$cacheName; // if not in cache, get data if (!$data) { $data = $this->executeJsonRequest($serviceName, $userName); // save data in the cache for next time $this->dataCache->$cacheName = $data; } return $data; } ... }
  21. 21. 21Fresche Solutions | BCD - looksoftware - Quadrant Flexibility
  22. 22. 22Fresche Solutions | BCD - looksoftware - Quadrant Flexibility Request http://host:port/web/services/LoadColumnInfo/LoadCreditHdr Response { "ColInf": [ { "Column": "Dlr", "Text": "Dealer", "FilterType": "DropDown", "DefaultFlag": "Y", "FieldLength": "10", "FldDecimal": "" }, { "Column": "CrtNo", "Text": "Credit #", "FilterType": "Alpha", "DefaultFlag": "Y", "FieldLength": "7", "FldDecimal": "" }... ] }
  23. 23. 23Fresche Solutions | BCD - looksoftware - Quadrant Responsive ■ Responsivity built into Bootstrap ■ One code base, all resolutions, full functionality
  24. 24. 24Fresche Solutions | BCD - looksoftware - Quadrant Dashboard Components File to Describe Components ■ Title ■ Route ■ Url ■ Icon ■ Background Image ■ Background Color ■ Sequence ■ Bootstrap Column Widths
  25. 25. 25Fresche Solutions | BCD - looksoftware - Quadrant Component Class ■ Each component within the system extended this Component Class. ■ New components are easy to create and plug into the application class ComponentController extends AbstractActionController { // Main Component View public function indexAction(){} // Tile View public function tileAction(){} // Mini Tile View public function minitileAction(){} // Grid Data Action public function dataAction(){} }
  26. 26. 26Fresche Solutions | BCD - looksoftware - Quadrant Lessons Learned ■ Communication, Communication, Communication ▶ good documentation and communication between the web service team and the front end team is key ■ RPG and PHP developers can both use their strengths ■ Your current RPG developers can still control and maintain your key business logic ■ Your system doesn’t have to be re-written ■ Your front end can be platform independent
  27. 27. Questions Chelsea Fenton chelsea.fenton@freschesolutions.com @chelseafenton2 www.freschesolutions.com

×