1 / 13

REST Introduction

REST Introduction. REST Concept. REST is R epresentational S tate T ransfer between Resource A style of software architecture A Virtual state-machine A network of web pages (a virtual state-machine),

kaycee
Download Presentation

REST Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. REST Introduction

  2. REST Concept REST is Representational State Transfer between Resource A style of software architecture A Virtual state-machine A network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use.

  3. REST Data Elements • Resources and Resource Identifiers • Uniform Interface (GET, PUT, POST, DELETE) • Resource Oriented

  4. REST Data Elements • Representations • HTML / XML / images / sounds / …

  5. REST V.S. SOAP • SOAP • Simple Object Access Protocol • RPC protocol that go through firewalls • Communication protocol between applications • A format for sending messages

  6. REST V.S. SOAP • REST • “The Web is the universe of globally accessible information” • Resource oriented • User-driven interactions via forms • Few operations (generic interface) on many resources • URI: Consistent naming mechanism for resources • Focus on scalability and performance of large scale distributed hypermedia systems • SOAP • “The Web is the universal transport for messages” • Activity/Service oriented • Orchestrated reliable event flows • Many operations (service interface) on few resources • Lack of standard naming mechanism • Focus on design of integrated (distributed) applications

  7. REST V.S. SOA • Two of most common styles of use of Web Services • Service-oriented architecture • “Message oriented” (SOAP) • Contract provided by WSDL • REST • Focus on interacting with stateful resources, rather than messages or operations.

  8. Slim Framework http://www.slimframework.com/

  9. Slim Framework • Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs. • One of the features – powerful routing • REST URI

  10. Slim Framework Install in c:\xampp\htdocs\slim Access: http://localhost/slim/ Apache .htaccess (to allow routing access in the index.php) <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>

  11. Slim Framework REST Hello World require 'Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); //REST routing with inline function $app->get('/hello/:name', function ($name) { echo "Hello, $name"; }); In browser url: http://localhost/slim/hello/jb In browser output: Hello, jb

  12. Slim Framework REST Calculator function doSum($num1, $num2) { $total = $num1 + $num2; echo "$num1 + $num2 = $total"; } //REST routing with external function and 2 parameters //Sample link: http://localhost/slim/calc/2/3 $app->get('/calc/:num1/:num2', 'doSum'); In browser url: http://localhost/slim/calc/2/3 In browser output: 2 + 3 = 5

  13. Slim Framework Returning JSON function doSumJson($num1, $num2) { $total = $num1 + $num2; $calc = new Calc(); $calc->num1 = $num1; $calc->num2 = $num2; $calc->total = $total; echo json_encode($calc); } //Returning a json $app->get('/calcjson/:num1/:num2', 'doSumJson'); In browser url: http://localhost/slim/calcjson/2/3 In browser output: {"num1":"2","num2":"3","total":5}

More Related