• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Taking Care of The REST - Creating your own RESTful API Server using Restler 2.0
 

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

on

  • 6,150 views

Restler 2.0 (https://github.com/Luracast/Restler) is a single file framework that can host public and protected methods of your PHP class as public and protected api respectively. This presentation ...

Restler 2.0 (https://github.com/Luracast/Restler) is a single file framework that can host public and protected methods of your PHP class as public and protected api respectively. This presentation talks about the opportunities in todays world and how easy it is to take them using Restler 2.0

Statistics

Views

Total Views
6,150
Views on SlideShare
6,146
Embed Views
4

Actions

Likes
5
Downloads
79
Comments
5

2 Embeds 4

https://twitter.com 3
http://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

15 of 5 previous next Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Yes, René, Let me find it and ping you!
    Are you sure you want to
    Your message goes here
    Processing…
  • Hi Arul,

    is the source of singmood still available?

    Best,
    René
    Are you sure you want to
    Your message goes here
    Processing…
  • @deusdustin There is no performance loss as we do not keep parsing the comments on production mode. placing things in comments helps us achieve many things in one go. For one example take a look at at the api explorer in this v3 example http://restler3.luracast.com/examples/_008_documentation/readme.html
    Are you sure you want to
    Your message goes here
    Processing…
  • Nice project and good luck for the future but in one point i couldn't understand your decision. The usage of 'JAVADOC style' propertys as access modifiers is a very bad coding style becouse performance loss and missing of object orientation. The control flow should be always embedded in the programming language.
    Are you sure you want to
    Your message goes here
    Processing…
  • Great stuff!!
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

    • TAKING CARE OF THE REST Creating your own RESTful API ServerMonday, 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 speakMonday, 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 denominatorMonday, 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 performanceMonday, 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 simpleMonday, June 20, 2011
    • GETTING STARTED Creating a hello world example in 3 stepsMonday, 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.phpMonday, June 20, 2011
    • STEP-2 COPY RESTLER ‣ Copy restler.php to the same web restler.php root ‣ It contains all the needed classes and interfacesMonday, 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 classMonday, June 20, 2011
    • CONSUMING OUR API Understanding how url mapping worksMonday, June 20, 2011
    • URL MAPPING base_path/{gateway}/{class_name} base_path/index.php/simple mapped to the result of index() method in Simple classMonday, 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 classMonday, 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 itselfMonday, June 20, 2011
    • PASSING PARAMETERS .../{class_name}?param1=value&param2=value .../simple?n1=4&n2=5 named parameters passed as query stringMonday, 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 ✓ObjectsMonday, 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 - YAMLMonday, 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 methodsMonday, 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 EXAMPLEMonday, June 20, 2011
    • ABOUT LURACASTMonday, June 20, 2011