Presentation is loading. Please wait.

Presentation is loading. Please wait.

REST Introduction. REST Concept REST is between Resource R epresentational S tate T ransfer between Resource A style of software architecture A Virtual.

Similar presentations


Presentation on theme: "REST Introduction. REST Concept REST is between Resource R epresentational S tate T ransfer between Resource A style of software architecture A Virtual."— Presentation transcript:

1 REST Introduction

2 REST Concept REST is between Resource 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), 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 Resources and Resource Identifiers Uniform Interface (GET, PUT, POST, DELETE) Resource Oriented REST Data Elements HTTPMethodCRUD Desc. POSTCREATECreate- GETRETRIEVERetrieveSafe,Idempotent,Cacheable PUTUPDATEUpdateIdempotent DELETE DeleteIdempotent

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

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

6 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 REST V.S. SOAP

7 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. REST V.S. SOA

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

9 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 Slim Framework

10 Install in c:\xampp\htdocs\slim Access: http://localhost/slim/ Slim Framework Apache.htaccess (to allow routing access in the index.php) Options -MultiViews 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]

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

12 REST Calculator Slim Framework 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 Returning JSON Slim Framework 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}


Download ppt "REST Introduction. REST Concept REST is between Resource R epresentational S tate T ransfer between Resource A style of software architecture A Virtual."

Similar presentations


Ads by Google