SlideShare a Scribd company logo
1 of 25
Download to read offline
TAKING CARE OF THE REST
                        Creating your own RESTful API Server




Monday, June 20, 2011
WHAT’S HAPPENING?



    ‣   We are in the Middle of a Revolution

    ‣   Devices and Tablets are taking over and changing the way we do things

    ‣   New devices and capabilities are arriving as we speak



Monday, June 20, 2011
WHAT THIS MEANS TO US, DEVELOPERS?


    ‣   More platforms to Explore

    ‣   Thus, more opportunities to Monetize

    ‣   Devices Divide, Developers Rule!




Monday, June 20, 2011
WHAT THIS MEANS TO US, DEVELOPERS?


    ‣   More platforms to Explore

    ‣   Thus, more opportunities to Monetize

    ‣   Devices Divide, Developers Rule!




Monday, June 20, 2011
HOW TO KEEP UP AND EXPAND ASAP?
    ‣   Create your API Server to serve data
        and some logic
    ‣   Create Hybrid Applications if possible
        ‣ HTML5
        ‣ Native (PhoneGap, Custom etc)

    ‣   Use cross-platform tools
        ‣ Adobe Flash, Flex, and AIR
        ‣ Titanium, Mosync etc

    ‣   Use least common denominator

Monday, June 20, 2011
WHY TO CREATE YOUR OWN API SERVER?
         ‣   It has the following Advantages
             • It  will serve as the remote model for your
                 apps
             • It  can hold some business logic for all your
                 apps
             • It       can be consumed from Web/Mobile/Desktop
             • It       can be exposed to 3rd party developers
             • It  can serve data in different formats to best
                 suite the device performance


Monday, June 20, 2011
HOW TO CREATE YOUR OWN API SERVER?
         ‣   Leverage on HTTP protocol
         ‣   Use REST (Representational State
             Transfer)
         ‣   Use different formats
             • Json (JavaScript Object Notation)
             • XML (eXtended Markup Language)
             • Plist (XML/Binary Property List)
             • Amf (Action Messaging Format)


Monday, June 20, 2011
INTRODUCING LURACAST RESTLER
         ‣   Easy to use RESTful API Server
         ‣   Light weight Micro-framework
         ‣   Supports many formats with two way
             auto conversion
         ‣   Written in PHP
         ‣   Free
         ‣   Open source (LGPL)

Monday, June 20, 2011
IF YOU KNOW OBJECT ORIENTED PHP


    ‣   You already know how to use RESTLER

    ‣   Its that simple




Monday, June 20, 2011
GETTING STARTED
                        Creating a hello world example in 3 steps




Monday, June 20, 2011
STEP-1 CREATE YOUR CLASS
         <?php
         class Simple {               ‣   Create a class and define its
         ! function index() {
         ! ! return 'Hello World!';
                                          methods
         ! }
         ! function sum($n1, $n2) {   ‣   Save it in root of your web site
         ! ! return $n1+$n2;
         ! }                              and name it in lower case
         }                                with .php extension
                  simple.php



Monday, June 20, 2011
STEP-2 COPY RESTLER

                                   ‣   Copy restler.php to the same web
                  restler.php          root

                                   ‣   It contains all the needed classes
                                       and interfaces




Monday, June 20, 2011
STEP-3 CREATE GATEWAY
                         <?php
                         spl_autoload_register();
                         $r = new Restler();
                         $r->addAPIClass('Simple');
                         $r->handle();
                                       index.php
         ‣   Create index.php
                                             ‣   Add Simple as the API class
         ‣   Create an instance of Restler
                                             ‣   Call the handle() method
             class


Monday, June 20, 2011
CONSUMING OUR API
                        Understanding how url mapping works




Monday, June 20, 2011
URL MAPPING




                        base_path/{gateway}/{class_name}
                        base_path/index.php/simple
                          mapped to the result of index() method in Simple class




Monday, June 20, 2011
URL MAPPING




 base_path/{gateway}/{class_name}/{method_name}
                    base_path/index.php/simple/sum
                        mapped to the result of sum() method in Simple class




Monday, June 20, 2011
ADVANCED URL MAPPING
    ‣   Use .htaccess file to remove      DirectoryIndex index.php
                                         <IfModule mod_rewrite.c>
        the index.php from the url       ! RewriteEngine On
                                         ! RewriteRule ^$ index.php [QSA,L]
        (http://rest.ler/simple/sum)     ! RewriteCond %{REQUEST_FILENAME} !-f
                                         ! RewriteCond %{REQUEST_FILENAME} !-d
                                         ! RewriteRule ^(.*)$ index.php [QSA,L]
                                         </IfModule>
    ‣   Pass an empty string as the
        second parameter for             <?php
        addAPIClass() method             spl_autoload_register();
        (http://rest.ler/sum)            $r = new Restler();
                                         $r->addAPIClass('Simple','');
                                         $r->handle();
    ‣   These are just conventions, we
        can use a javadoc style      /**
        comment to configure          * @url GET math/add
        (http://rest.ler/math/add) */function sum($n1, $n2)        {
                                       ! return $n1+$n2;
                                       }
Monday, June 20, 2011
PASSING PARAMETERS




                        .../{class_name}/{param1}/{param2}
                                   .../simple/4/5
                              parameters are passed in order as url itself




Monday, June 20, 2011
PASSING PARAMETERS




        .../{class_name}?param1=value&param2=value
                        .../simple?n1=4&n2=5
                         named parameters passed as query string




Monday, June 20, 2011
RETURNING COMPLEX DATA
         <?php
         class Simple {
         ! function index() {
                                             ‣   Restler can handle all the
         ! ! return 'Hello World!';              following PHP types
         ! }
         ! function sum($n1, $n2) {
         ! ! return array('sum'=>$n1+$n2);
         ! }                                     ✓Number
         }

                                                 ✓Boolean   (True | False)

                                                 ✓String

                                                 ✓Indexed/Associative   array

                                                 ✓Objects


Monday, June 20, 2011
SUPPORTING FORMATS
       <?php
       $r = new Restler();             ‣   Step1 - Copy the format file(s)
       $r->addAPIClass('Simple','');
       $r->setSupportedFormats(        ‣   Step2 - Call setSupportedFormats()
            'XmlFormat','JsonFormat'       method and pass the formats
       );
       $r->handle();
                                       ‣   Restler supports the following
                                           formats
                                           -   JSON
                                           -   XML
                                           -   Plist
                                           -   AMF
                                           -   YAML

Monday, June 20, 2011
PROTECTING SOME OF THE API
    <?php
    class SimpleAuth implements iAuthenticate{
    ! function __isAuthenticated() {
    ! ! return $_GET['token']=='178261dsjdkjho8f' ? TRUE : FALSE;
    ! }
    }


    <?php
    $r = new Restler();                         ‣   Step1 - Create an Auth Class
    $r->addAPIClass('Simple','');
    $r->setSupportedFormats(                        implementing iAuthenicate interface
       'XmlFormat','JsonFormat'
    );
    $r->addAuthenticationClass('SimpleAuth');   ‣   Step2 - Call addAuthenticationClass()
    $r->handle();
                                                    method and pass that class
     protected function sum($n1, $n2) {         ‣   Simply change the methods to be
     ! return array('sum'=>$n1+$n2);
     }                                              protected as protected methods

Monday, June 20, 2011
USING HTTP METHODS & CRUD

      <?php
      class User {
      ! $dp = new DataProvider('User');            ‣   GET - Retrieve
      ! function get() {
      ! ! return $this->dp->getAll();
      ! }
      ! function post($data) {                     ‣   POST - Create
      ! ! return $this->dp->create($data);
      ! }
      ! function put($idx, $data) {
      ! ! return $this->dp->update($idx, $data);
                                                   ‣   PUT - Update
      ! }
      ! function delete($idx, $data) {
      ! ! return $this->dp->delete($idx, $data);   ‣   DELETE - Delete
      ! }
      }




Monday, June 20, 2011
REAL WORLD RESTLER EXAMPLE




Monday, June 20, 2011
ABOUT LURACAST




Monday, June 20, 2011

More Related Content

What's hot

Maintaining sanity in a large redux app
Maintaining sanity in a large redux appMaintaining sanity in a large redux app
Maintaining sanity in a large redux appNitish Kumar
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netProgrammer Blog
 
Interchange 6 - Open Source Shop Machine
Interchange 6 - Open Source Shop MachineInterchange 6 - Open Source Shop Machine
Interchange 6 - Open Source Shop MachineLinuXia
 
Drupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire WorldDrupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire WorldChristian López Espínola
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSmohdoracle
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in phpAshish Chamoli
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 TrainingChris Chubb
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sqlÑirmal Tatiwal
 
Reactive cocoa
Reactive cocoaReactive cocoa
Reactive cocoaiacisclo
 
Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11Pedro Cunha
 
08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboardsDenis Ristic
 
Programming in Oracle with PL/SQL
Programming in Oracle with PL/SQLProgramming in Oracle with PL/SQL
Programming in Oracle with PL/SQLlubna19
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 TrainingChris Chubb
 
Db Triggers05ch
Db Triggers05chDb Triggers05ch
Db Triggers05chtheo_10
 
PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2Kumar
 
The ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThe ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThoughtWorks
 

What's hot (20)

Packages - PL/SQL
Packages - PL/SQLPackages - PL/SQL
Packages - PL/SQL
 
Maintaining sanity in a large redux app
Maintaining sanity in a large redux appMaintaining sanity in a large redux app
Maintaining sanity in a large redux app
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
 
Interchange 6 - Open Source Shop Machine
Interchange 6 - Open Source Shop MachineInterchange 6 - Open Source Shop Machine
Interchange 6 - Open Source Shop Machine
 
Drupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire WorldDrupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire World
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERS
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 Training
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
Reactive cocoa
Reactive cocoaReactive cocoa
Reactive cocoa
 
Licão 13 functions
Licão 13 functionsLicão 13 functions
Licão 13 functions
 
Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11
 
08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards
 
Programming in Oracle with PL/SQL
Programming in Oracle with PL/SQLProgramming in Oracle with PL/SQL
Programming in Oracle with PL/SQL
 
My sql
My sqlMy sql
My sql
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 Training
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
 
Db Triggers05ch
Db Triggers05chDb Triggers05ch
Db Triggers05ch
 
PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2
 
The ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThe ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj Kumar
 

Viewers also liked

Testing and Documenting Pragmatic / RESTful Web API
Testing and Documenting Pragmatic / RESTful Web APITesting and Documenting Pragmatic / RESTful Web API
Testing and Documenting Pragmatic / RESTful Web APIArul Kumaran
 
Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.xRyan Szrama
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswanivvaswani
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP TutorialLorna Mitchell
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기RESTful API 제대로 만들기
RESTful API 제대로 만들기Juwon Kim
 

Viewers also liked (6)

Testing and Documenting Pragmatic / RESTful Web API
Testing and Documenting Pragmatic / RESTful Web APITesting and Documenting Pragmatic / RESTful Web API
Testing and Documenting Pragmatic / RESTful Web API
 
Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.x
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP Tutorial
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기RESTful API 제대로 만들기
RESTful API 제대로 만들기
 

Similar to Taking Care of The REST - Creating your own RESTful API Server using Restler 2.0

Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHPNick Belhomme
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7ZendVN
 
From CakePHP to Laravel
From CakePHP to LaravelFrom CakePHP to Laravel
From CakePHP to LaravelJason McCreary
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
02 - Second meetup
02 - Second meetup02 - Second meetup
02 - Second meetupEdiPHP
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroChristopher Pecoraro
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricksFilip Golonka
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
PHP Versions Upgradation - What's New vs Old Version.pdf
PHP Versions Upgradation - What's New vs Old Version.pdfPHP Versions Upgradation - What's New vs Old Version.pdf
PHP Versions Upgradation - What's New vs Old Version.pdfWPWeb Infotech
 
Creating a modern web application using Symfony API Platform Atlanta
Creating a modern web application using  Symfony API Platform AtlantaCreating a modern web application using  Symfony API Platform Atlanta
Creating a modern web application using Symfony API Platform AtlantaJesus Manuel Olivas
 
Elements of Functional Programming in PHP
Elements of Functional Programming in PHPElements of Functional Programming in PHP
Elements of Functional Programming in PHPJarek Jakubowski
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...King Foo
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPwahidullah mudaser
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Jesus Manuel Olivas
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQLArti Parab Academics
 

Similar to Taking Care of The REST - Creating your own RESTful API Server using Restler 2.0 (20)

Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
OOP
OOPOOP
OOP
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
From CakePHP to Laravel
From CakePHP to LaravelFrom CakePHP to Laravel
From CakePHP to Laravel
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
02 - Second meetup
02 - Second meetup02 - Second meetup
02 - Second meetup
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricks
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
PHP Versions Upgradation - What's New vs Old Version.pdf
PHP Versions Upgradation - What's New vs Old Version.pdfPHP Versions Upgradation - What's New vs Old Version.pdf
PHP Versions Upgradation - What's New vs Old Version.pdf
 
Creating a modern web application using Symfony API Platform Atlanta
Creating a modern web application using  Symfony API Platform AtlantaCreating a modern web application using  Symfony API Platform Atlanta
Creating a modern web application using Symfony API Platform Atlanta
 
Elements of Functional Programming in PHP
Elements of Functional Programming in PHPElements of Functional Programming in PHP
Elements of Functional Programming in PHP
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 

More from Arul Kumaran

Getting out of Callback Hell in PHP
Getting out of Callback Hell in PHPGetting out of Callback Hell in PHP
Getting out of Callback Hell in PHPArul Kumaran
 
Accelerating Xamarin Development
Accelerating Xamarin DevelopmentAccelerating Xamarin Development
Accelerating Xamarin DevelopmentArul Kumaran
 
iOS Native Development with Xamarin
iOS Native Development with XamariniOS Native Development with Xamarin
iOS Native Development with XamarinArul Kumaran
 
Less Verbose ActionScript 3.0 - Write less and do more!
Less Verbose ActionScript 3.0 - Write less and do more!Less Verbose ActionScript 3.0 - Write less and do more!
Less Verbose ActionScript 3.0 - Write less and do more!Arul Kumaran
 
Using Titanium for multi-platform development including iPhone and Android
Using Titanium for multi-platform development including iPhone and AndroidUsing Titanium for multi-platform development including iPhone and Android
Using Titanium for multi-platform development including iPhone and AndroidArul Kumaran
 
UI Interactions Testing with FlexMonkey
UI Interactions Testing with FlexMonkeyUI Interactions Testing with FlexMonkey
UI Interactions Testing with FlexMonkeyArul Kumaran
 
Flex Production Tips & Techniques
Flex Production Tips & TechniquesFlex Production Tips & Techniques
Flex Production Tips & TechniquesArul Kumaran
 

More from Arul Kumaran (7)

Getting out of Callback Hell in PHP
Getting out of Callback Hell in PHPGetting out of Callback Hell in PHP
Getting out of Callback Hell in PHP
 
Accelerating Xamarin Development
Accelerating Xamarin DevelopmentAccelerating Xamarin Development
Accelerating Xamarin Development
 
iOS Native Development with Xamarin
iOS Native Development with XamariniOS Native Development with Xamarin
iOS Native Development with Xamarin
 
Less Verbose ActionScript 3.0 - Write less and do more!
Less Verbose ActionScript 3.0 - Write less and do more!Less Verbose ActionScript 3.0 - Write less and do more!
Less Verbose ActionScript 3.0 - Write less and do more!
 
Using Titanium for multi-platform development including iPhone and Android
Using Titanium for multi-platform development including iPhone and AndroidUsing Titanium for multi-platform development including iPhone and Android
Using Titanium for multi-platform development including iPhone and Android
 
UI Interactions Testing with FlexMonkey
UI Interactions Testing with FlexMonkeyUI Interactions Testing with FlexMonkey
UI Interactions Testing with FlexMonkey
 
Flex Production Tips & Techniques
Flex Production Tips & TechniquesFlex Production Tips & Techniques
Flex Production Tips & Techniques
 

Recently uploaded

Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 

Recently uploaded (20)

Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 

Taking Care of The REST - Creating your own RESTful API Server using Restler 2.0

  • 1. TAKING CARE OF THE REST Creating your own RESTful API Server Monday, June 20, 2011
  • 2. WHAT’S HAPPENING? ‣ We are in the Middle of a Revolution ‣ Devices and Tablets are taking over and changing the way we do things ‣ New devices and capabilities are arriving as we speak Monday, June 20, 2011
  • 3. WHAT THIS MEANS TO US, DEVELOPERS? ‣ More platforms to Explore ‣ Thus, more opportunities to Monetize ‣ Devices Divide, Developers Rule! Monday, June 20, 2011
  • 4. WHAT THIS MEANS TO US, DEVELOPERS? ‣ More platforms to Explore ‣ Thus, more opportunities to Monetize ‣ Devices Divide, Developers Rule! Monday, June 20, 2011
  • 5. HOW TO KEEP UP AND EXPAND ASAP? ‣ Create your API Server to serve data and some logic ‣ Create Hybrid Applications if possible ‣ HTML5 ‣ Native (PhoneGap, Custom etc) ‣ Use cross-platform tools ‣ Adobe Flash, Flex, and AIR ‣ Titanium, Mosync etc ‣ Use least common denominator Monday, June 20, 2011
  • 6. WHY TO CREATE YOUR OWN API SERVER? ‣ It has the following Advantages • It will serve as the remote model for your apps • It can hold some business logic for all your apps • It can be consumed from Web/Mobile/Desktop • It can be exposed to 3rd party developers • It can serve data in different formats to best suite the device performance Monday, June 20, 2011
  • 7. HOW TO CREATE YOUR OWN API SERVER? ‣ Leverage on HTTP protocol ‣ Use REST (Representational State Transfer) ‣ Use different formats • Json (JavaScript Object Notation) • XML (eXtended Markup Language) • Plist (XML/Binary Property List) • Amf (Action Messaging Format) Monday, June 20, 2011
  • 8. INTRODUCING LURACAST RESTLER ‣ Easy to use RESTful API Server ‣ Light weight Micro-framework ‣ Supports many formats with two way auto conversion ‣ Written in PHP ‣ Free ‣ Open source (LGPL) Monday, June 20, 2011
  • 9. IF YOU KNOW OBJECT ORIENTED PHP ‣ You already know how to use RESTLER ‣ Its that simple Monday, June 20, 2011
  • 10. GETTING STARTED Creating a hello world example in 3 steps Monday, June 20, 2011
  • 11. STEP-1 CREATE YOUR CLASS <?php class Simple { ‣ Create a class and define its ! function index() { ! ! return 'Hello World!'; methods ! } ! function sum($n1, $n2) { ‣ Save it in root of your web site ! ! return $n1+$n2; ! } and name it in lower case } with .php extension simple.php Monday, June 20, 2011
  • 12. STEP-2 COPY RESTLER ‣ Copy restler.php to the same web restler.php root ‣ It contains all the needed classes and interfaces Monday, June 20, 2011
  • 13. STEP-3 CREATE GATEWAY <?php spl_autoload_register(); $r = new Restler(); $r->addAPIClass('Simple'); $r->handle(); index.php ‣ Create index.php ‣ Add Simple as the API class ‣ Create an instance of Restler ‣ Call the handle() method class Monday, June 20, 2011
  • 14. CONSUMING OUR API Understanding how url mapping works Monday, June 20, 2011
  • 15. URL MAPPING base_path/{gateway}/{class_name} base_path/index.php/simple mapped to the result of index() method in Simple class Monday, June 20, 2011
  • 16. URL MAPPING base_path/{gateway}/{class_name}/{method_name} base_path/index.php/simple/sum mapped to the result of sum() method in Simple class Monday, June 20, 2011
  • 17. ADVANCED URL MAPPING ‣ Use .htaccess file to remove DirectoryIndex index.php <IfModule mod_rewrite.c> the index.php from the url ! RewriteEngine On ! RewriteRule ^$ index.php [QSA,L] (http://rest.ler/simple/sum) ! RewriteCond %{REQUEST_FILENAME} !-f ! RewriteCond %{REQUEST_FILENAME} !-d ! RewriteRule ^(.*)$ index.php [QSA,L] </IfModule> ‣ Pass an empty string as the second parameter for <?php addAPIClass() method spl_autoload_register(); (http://rest.ler/sum) $r = new Restler(); $r->addAPIClass('Simple',''); $r->handle(); ‣ These are just conventions, we can use a javadoc style /** comment to configure * @url GET math/add (http://rest.ler/math/add) */function sum($n1, $n2) { ! return $n1+$n2; } Monday, June 20, 2011
  • 18. PASSING PARAMETERS .../{class_name}/{param1}/{param2} .../simple/4/5 parameters are passed in order as url itself Monday, June 20, 2011
  • 19. PASSING PARAMETERS .../{class_name}?param1=value&param2=value .../simple?n1=4&n2=5 named parameters passed as query string Monday, June 20, 2011
  • 20. RETURNING COMPLEX DATA <?php class Simple { ! function index() { ‣ Restler can handle all the ! ! return 'Hello World!'; following PHP types ! } ! function sum($n1, $n2) { ! ! return array('sum'=>$n1+$n2); ! } ✓Number } ✓Boolean (True | False) ✓String ✓Indexed/Associative array ✓Objects Monday, June 20, 2011
  • 21. SUPPORTING FORMATS <?php $r = new Restler(); ‣ Step1 - Copy the format file(s) $r->addAPIClass('Simple',''); $r->setSupportedFormats( ‣ Step2 - Call setSupportedFormats() 'XmlFormat','JsonFormat' method and pass the formats ); $r->handle(); ‣ Restler supports the following formats - JSON - XML - Plist - AMF - YAML Monday, June 20, 2011
  • 22. PROTECTING SOME OF THE API <?php class SimpleAuth implements iAuthenticate{ ! function __isAuthenticated() { ! ! return $_GET['token']=='178261dsjdkjho8f' ? TRUE : FALSE; ! } } <?php $r = new Restler(); ‣ Step1 - Create an Auth Class $r->addAPIClass('Simple',''); $r->setSupportedFormats( implementing iAuthenicate interface 'XmlFormat','JsonFormat' ); $r->addAuthenticationClass('SimpleAuth'); ‣ Step2 - Call addAuthenticationClass() $r->handle(); method and pass that class protected function sum($n1, $n2) { ‣ Simply change the methods to be ! return array('sum'=>$n1+$n2); } protected as protected methods Monday, June 20, 2011
  • 23. USING HTTP METHODS & CRUD <?php class User { ! $dp = new DataProvider('User'); ‣ GET - Retrieve ! function get() { ! ! return $this->dp->getAll(); ! } ! function post($data) { ‣ POST - Create ! ! return $this->dp->create($data); ! } ! function put($idx, $data) { ! ! return $this->dp->update($idx, $data); ‣ PUT - Update ! } ! function delete($idx, $data) { ! ! return $this->dp->delete($idx, $data); ‣ DELETE - Delete ! } } Monday, June 20, 2011
  • 24. REAL WORLD RESTLER EXAMPLE Monday, June 20, 2011