SlideShare a Scribd company logo
1 of 32
Download to read offline
Bangalore PHP User Group – 31 October 2009




Building RESTful Applications Using
              PHP


                    Sudheer Satyanarayana
                        http://techchorus.net
                        http://binaryvibes.co.in
About Your Presenter

Director, Binary Vibes Information Technologies
 Pvt. Ltd (http://binaryvibes.co.in)

Free and open source software supporter

PHP programmer

Blogger - http://techchorus.net
Topics


What is REST?

Why REST?

How to use REST?
What Is REST?


Representational State Transfer

Style of software architecture

Introduced by Roy Fielding
Six Constraints Describe The Architectural Style

Client Server

Statelessness

Cacheable

Uniform interface

Layered system

Code on demand
Constraint 1: Separation Of Clients And Servers
Clients

Browser

PHP/Python/Perl/Whatever script

Desktop application

Command line

Anything that can make an HTTP request
Advantages Of Separation Of Clients And Servers


  Portability: clients are not bothered about data
storage

  Scalibility: servers are not bothered about user
interface

 Independent development of clients and servers
Constraint 2: Statelessness

 HTTP is stateless

 Server does not store client context

 Clients may hold context

  Each request contains all information
required to process the request
Advantages Of Statelessness

Servers are more scalable

Servers are more reliable

Servers are more visible for monitoring
Constraint 3 : Cacheable


 Responses indicate whether they are
cacheable

 Eliminates some client server interactions
Advantages Of Cacheability

Performance

Scalability
Constraint 4: Uniform Interface

REST is defined by four interface constraints

 Identification of resources

  Manipulation of resources through
representations

 Self descriptive messages

 Hypermedia as the engine of application state
Identification Of Resources

Resource can be anything
 Article
 Comment
 Contact
 User
 Employee
 URI – Uniform Resource Identifier
 http://example.com/article/1
 http://example.com/comment
 http://example.com/article?title=abc
Manipulation Of Resrources Through Representations

Use the HTTP verbs

 GET – retrieve one or a collection of articles
 POST – create a resource
 PUT – modify an article
 DELETE – delete an article


 http://example.com/article   GET      Return collection of articles
 http://example.com/article/1 GET      Return article whose id is 1
 http://example.com/article   POST     Create an article
 http://example.com/article/1 PUT      Modify the article whose id is 1
 http://example.com/article/1 DELETE   Delete the article whose id is 1
Self Descriptive Messages

HTTP Headers
HTTP Response Codes

1XX Informational
2XX Success
  200 Ok
  201 Created
  202 Accepted
  204 No Content
3XX Redirection
4XX Client Error
  403 Forbidden
  404 Not Found
5XX Server Error
Hypermedia As The Engine Of Application State

Provide sufficient information to access related
resources

 When http://example.com/article/1 is accessed
 Inform the client how to access the comments of
article 1

Mention http://example.com/comments?criteria=byarticle&articleid=1
in the response
Constraint 5 : Layered System

Proxies, gateways and other intermediaries

 Encapsulate legacy services

 Protect new services from legacy clients

 Load balancing

 High performance
Constraint 6: Code On Demand (Optional)

 Client downloads code from server and
executes it
 Common example: Server generating
JavaScript code
If your system conforms to these constraints it
can be called

                   RESTful
REST Advantages
Performance

Scalability

Simplicity

Modifiability

Visibility

Portability

Reliability
Tips to put these concepts into practice
PHP header() function

Use header() function to describe the response
headers

header("HTTP/1.0 404 Not Found");
header(”Location: http://example.com/movedhere”);
header('Content-type: application/xml);
header('Content-type: application/json);
Determine the request method

$_SERVER['REQUEST_METHOD']
Use cUrl from the CLI to test REST server

 Write a PHP script to make HTTP requests

 PHP supports curl, use the PHP curl_* functions

 Streams and sockets functions are also available

Telnet also works
Use Apache's mod_rewrite to make URLs pretty

Other web servers offer similar functionality

$_SERVER['REQUEST_URI']
Encode data to and decode from JSON

json_encode()
json_decode()
Authentication

HTTP Authentication

API Key in HTTP header
 apache_request_headers()
 $_SERVER
Your favourite PHP framework might have a
component to help develop RESTful servers

 Use it
Questions?
Contact me

http://twitter.com/bngsudheer
http://techchorus.net
IRC, Bonaparte on freenode.net



                Thank you
Copyright Notice



This presentation is licensed under the Creative Commons Attribution-
Noncommercial-Share Alike 2.5 India

http://creativecommons.org/licenses/by-nc-sa/2.5/in/

More Related Content

What's hot

Web Servers: Architecture and Security
Web Servers: Architecture and SecurityWeb Servers: Architecture and Security
Web Servers: Architecture and Security
george.james
 
HTML5 Server Sent Events/JSF JAX 2011 Conference
HTML5 Server Sent Events/JSF  JAX 2011 ConferenceHTML5 Server Sent Events/JSF  JAX 2011 Conference
HTML5 Server Sent Events/JSF JAX 2011 Conference
Roger Kitain
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
Zoran Jeremic
 
Web Services - A brief overview
Web Services -  A brief overviewWeb Services -  A brief overview
Web Services - A brief overview
Raveendra Bhat
 

What's hot (20)

Web services - A Practical Approach
Web services - A Practical ApproachWeb services - A Practical Approach
Web services - A Practical Approach
 
Web Server-Side Programming Techniques
Web Server-Side Programming TechniquesWeb Server-Side Programming Techniques
Web Server-Side Programming Techniques
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
 
Webservice for android ppt
Webservice for android pptWebservice for android ppt
Webservice for android ppt
 
Web server
Web serverWeb server
Web server
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming Primer
 
Survey of restful web services frameworks
Survey of restful web services frameworksSurvey of restful web services frameworks
Survey of restful web services frameworks
 
Web servers
Web serversWeb servers
Web servers
 
Web Servers: Architecture and Security
Web Servers: Architecture and SecurityWeb Servers: Architecture and Security
Web Servers: Architecture and Security
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
 
HTML5 Server Sent Events/JSF JAX 2011 Conference
HTML5 Server Sent Events/JSF  JAX 2011 ConferenceHTML5 Server Sent Events/JSF  JAX 2011 Conference
HTML5 Server Sent Events/JSF JAX 2011 Conference
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
Web Services - A brief overview
Web Services -  A brief overviewWeb Services -  A brief overview
Web Services - A brief overview
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Overview of java web services
Overview of java web servicesOverview of java web services
Overview of java web services
 
Web Servers (ppt)
Web Servers (ppt)Web Servers (ppt)
Web Servers (ppt)
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 

Similar to Building Restful Applications Using Php

Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01
raviIITRoorkee
 
A Conversation About REST - Extended Version
A Conversation About REST - Extended VersionA Conversation About REST - Extended Version
A Conversation About REST - Extended Version
Jeremy Brown
 

Similar to Building Restful Applications Using Php (20)

Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
11 asp.net web api
11 asp.net web api11 asp.net web api
11 asp.net web api
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 
Rest API Automation with REST Assured
Rest API Automation with REST AssuredRest API Automation with REST Assured
Rest API Automation with REST Assured
 
Getting Started with API Management
Getting Started with API ManagementGetting Started with API Management
Getting Started with API Management
 
ReSTful API Final
ReSTful API FinalReSTful API Final
ReSTful API Final
 
IRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce Site
 
Api 101
Api 101Api 101
Api 101
 
Unerstanding and Using RESTful APIs
Unerstanding and Using RESTful APIsUnerstanding and Using RESTful APIs
Unerstanding and Using RESTful APIs
 
A Deep Dive into REST API Framework Survey
A Deep Dive into REST API Framework SurveyA Deep Dive into REST API Framework Survey
A Deep Dive into REST API Framework Survey
 
Understanding and Using Rest APIs (SocialDevCamp Chicago 2009)
Understanding and Using Rest APIs (SocialDevCamp Chicago 2009)Understanding and Using Rest APIs (SocialDevCamp Chicago 2009)
Understanding and Using Rest APIs (SocialDevCamp Chicago 2009)
 
Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01
 
Best Practices in Api Design
Best Practices in Api DesignBest Practices in Api Design
Best Practices in Api Design
 
ReST (Representational State Transfer) Explained
ReST (Representational State Transfer) ExplainedReST (Representational State Transfer) Explained
ReST (Representational State Transfer) Explained
 
A Conversation About REST - Extended Version
A Conversation About REST - Extended VersionA Conversation About REST - Extended Version
A Conversation About REST - Extended Version
 
RESTful web services using java and spring
RESTful web services using java and springRESTful web services using java and spring
RESTful web services using java and spring
 
Writing RESTful Web Services
Writing RESTful Web ServicesWriting RESTful Web Services
Writing RESTful Web Services
 
Rest WebAPI with OData
Rest WebAPI with ODataRest WebAPI with OData
Rest WebAPI with OData
 
Rest web service
Rest web serviceRest web service
Rest web service
 
Approaches to machine actionable links
Approaches to machine actionable linksApproaches to machine actionable links
Approaches to machine actionable links
 

More from Sudheer Satyanarayana (6)

XML For PHP Developers
XML For PHP DevelopersXML For PHP Developers
XML For PHP Developers
 
How To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHPHow To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHP
 
Introduction to-bizsense-bpug-29-05-2010
Introduction to-bizsense-bpug-29-05-2010Introduction to-bizsense-bpug-29-05-2010
Introduction to-bizsense-bpug-29-05-2010
 
Bare acl
Bare aclBare acl
Bare acl
 
Framework Shootout ZF
Framework Shootout ZFFramework Shootout ZF
Framework Shootout ZF
 
Mysql Naming Conventions Bangalore Mysql User Group Oct 11 09
Mysql Naming Conventions Bangalore Mysql User Group Oct 11 09Mysql Naming Conventions Bangalore Mysql User Group Oct 11 09
Mysql Naming Conventions Bangalore Mysql User Group Oct 11 09
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Building Restful Applications Using Php