SlideShare une entreprise Scribd logo
1  sur  45
Télécharger pour lire hors ligne
AmsterdamPHP



               Create a RESTful api
                        November 15, 2012
AmsterdamPHP
INTRODUCTION




                   Marc Ypes
                       @Ceeram


                   CakePHP 4 years
                  Core team 1.5 years
               Undercover as programmer


AmsterdamPHP
OVERVIEW


 ■   Content-types
 ■   Interface
 ■   Authentication
 ■   Cache
 ■   Errors




AmsterdamPHP
INTRODUCTION TO REST
 Representational state transfer

 Set of architectural principles

 - resource focussed
 - manipulation through representations
 - HTTP protocol?




AmsterdamPHP
INTRODUCTION TO REST
 Constraints

 ■   Client-server
 ■   Stateless
 ■   Uniform interface
 ■   Cacheable
 ■   Layered system




AmsterdamPHP
INTRODUCTION TO REST
 Client-server

 separation of concerns

 portability of UI across platforms, scalability

 allowing components to evolve independently




AmsterdamPHP
INTRODUCTION TO REST
 Stateless

 request includes required information

 no stored context on server: Sessions




AmsterdamPHP
INTRODUCTION TO REST
 Uniform interface

 information is transfered in standardized form

 using nouns for resources

 (http) protocol describes methods




AmsterdamPHP
INTRODUCTION TO REST
 Cacheable

 reducing latency

 lower serverload




AmsterdamPHP
INTRODUCTION TO REST
 Layered system

 Server
 Client

 Proxy
 Gateway
 Security
 Anything



AmsterdamPHP
INTRODUCTION TO REST
 Uniform interface

 ■ resource

 ■ identification of the resource

 ■ manipulation through representation

 ■ self-descriptive

 ■ hypermedia as the engine of application state
   HATEOAS
AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 Data element                Example
 resource                    user, book etc. (users, books etc.)
 resource identifier         URL, URN (/users/1234)
 representation
    data                     TXT / HTML / XML /YAML,JSON
    metadata                 content type, last-modified time
 resource metadata           source link, alternate
 control data                if-modified-since, cache-control, etag


 http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm


AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 /api/getUserProfile/1234

 /api/users?action=vote&id=1234

 /api/deleteUser?id=1




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 RPC style

 Steep learning curve
 Documentation
 New functionality, BC




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 2 base urls

 - /books
 - /books/1234




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 GET           /users        Get collection
 POST          /users        Add to collection
 GET           /users/1234   Get resource
 PUT           /users/1234   Update resource
 DELETE        /users/1234   Delete resource

 Update is not replace?
 POST       /users/1234

AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 Typical request:

 >GET /books/1849511926 HTTP/1.1
 >Host: api.amazin.com
 >Accept: application/json

 >If-Modified-Since: Sat, 01 Sep 2012 10:22:36 GMT



AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 Typical response:

 < HTTP/1.1 200 OK
 < Date: Sat, 01 Sep 2012 11:45:12 GMT
 < Server: Apache/2.2.16 (Debian)
 < Last-Modified: Sat, 01 Sep 2012 11:25:31 GMT
 < Content-Length: 145
 < Content-Type: application/json
 {"book":{........"}}
AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 Typical response:

 < HTTP/1.1 304 Not Modified
 < Date: Sat, 01 Sep 2012 11:45:12 GMT
 < Server: Apache/2.2.16 (Debian)
 < Vary: Accept-Encoding




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 Safe methods
 Idempotent methods

 GET (HEAD) is safe (nullipotent)
 PUT, DELETE are idempotent

 POST
 PATCH?

AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 Normalize the resources

 GET           /books/1849511926/votes

 GET           /votes?book=1849511926




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 Normalize the resources

 POST          /books/1849511926/votes

 PUT          /books/1849511926
 data contains votes subresource data

 POST         /votes
 data is book=1849511926

AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface

 PATCH

 Edge Rails: PATCH is the new primary HTTP method for updates




 http://weblog.rubyonrails.org/2012/2/25/edge-rails-patch-is-the-new-primary-http-method-for-updates/



AmsterdamPHP
INTRODUCTION TO REST
 Versioning

 /rest
 /v1

 content-type




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / HATEOAS

 Level 3 of REST maturity model (RMM)




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / HATEOAS

 Level 0

 Single URI, single HTTP method




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / HATEOAS

 Level 1

 Many URI, single HTTP method




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / HATEOAS

 Level 2

 Many URI, different HTTP methods




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / HATEOAS

 Level 3

 Self descriptive
 ■ Media types
 ■ Links
 ■ Other protocols




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / HATEOAS

 HATEOAS

 GET           /comments?book=1849511926

 Link to api.amazin.com/books/1849511926

 Links to all comments


AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / HATEOAS
 >GET      /comments/1
 <HTTP/1.1 200 Ok
 <Content-Type: text/xml
 <?xml version="1.0">
 <comment>
    <foo>great book</foo>
    <book>
       <link href="/books/1849511926" title="wow" />
    </book>
 </comment>
AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / HATEOAS
     {
         "foo":"great book",
         "book":
             {
                 "links":[
                     {
                          "href":"/books/1849511926",
                          "title":"wow"
                     }
                 ]
             }
     }
AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / HATEOAS

 Link header

 Link: <https://api.github.com/user/repos?page=2&per_page=100>;rel="
 next",
  <https://api.github.com/user/repos?page=50&per_page=100>;rel="last"




                               github.com
AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / Errors

 HTTP Statuscodes

 Human reads message
 Code reads code




AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / Errors

 HTTP Statuscodes

 200 OK
 201 Created
 204 No Content
 304 Not Modified
 400 Bad Request
 401 Unauthorized
 404 Not Found
 405 Method Not Allowed
AmsterdamPHP
INTRODUCTION TO REST
 Uniform Interface / Errors

 Link to support page

 Link: <http://api.amazin.com/errors/405>; rel="help"




AmsterdamPHP
REST my Cake
 Authentication

 Public
 Api-key
 Basic Auth
 OAuth




CakeFest 2012 Manchester
INTRODUCTION TO REST
 Cacheable

 HTTP Cache headers

 Use them!




AmsterdamPHP
INTRODUCTION TO REST
 Cacheable

 HTTP Cache headers

 Cache-control
 - private
 - public
 - max-age / s-maxage
 - must-revalidate
 - nocache


AmsterdamPHP
INTRODUCTION TO REST
 Cacheable

 HTTP Cache validation

 Etag                    Response
 Last-Modified           Response

 If-Modified-Since       Request (GET)
 If-None-Match           Request (GET)

 If-Match                Request (PUT)

AmsterdamPHP
REST my Cake
 CakeResponse

 header( $header = NULL, $value = NULL )
 send( )
 statusCode( $code = NULL )
 type( $contentType = NULL )




AmsterdamPHP
REST my Cake
 CakeResponse

 cache( $since, $time = '+1 day' )
 checkNotModified( $request )
 disableCache( )
 etag( $tag = NULL, $weak = false )
 expires( $time = NULL )
 maxAge( $seconds = NULL )
 modified( $time = NULL )
 mustRevalidate( $enable = NULL )
 notModified( )
 sharable( $public = NULL, $time = NULL )
 sharedMaxAge( $seconds = NULL )
AmsterdamPHP
REST my Cake

 CakePHP 3.0

 2013
 PHP 5.4
 composer
 arrays => objects




AmsterdamPHP
INTRODUCTION TO REST


 REST might not be what you are looking for

 Questions?




AmsterdamPHP
INTRODUCTION TO REST




                     THANKS

               https://joind.in/event/view/1141

AmsterdamPHP

Contenu connexe

Tendances

Crash course to the Apache Camel
Crash course to the Apache CamelCrash course to the Apache Camel
Crash course to the Apache CamelHenryk Konsek
 
JSON-RPC - JSON Remote Procedure Call
JSON-RPC - JSON Remote Procedure CallJSON-RPC - JSON Remote Procedure Call
JSON-RPC - JSON Remote Procedure CallPeter R. Egli
 
JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5Stephan Schmidt
 
PHP and Web Services
PHP and Web ServicesPHP and Web Services
PHP and Web ServicesBruno Pedro
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
Reaching Out From PL/SQL (OPP 2010)
Reaching Out From PL/SQL (OPP 2010)Reaching Out From PL/SQL (OPP 2010)
Reaching Out From PL/SQL (OPP 2010)Lucas Jellema
 
The Functional Web
The Functional WebThe Functional Web
The Functional WebRyan Riley
 
Xml Publisher And Reporting To Excel
Xml Publisher And Reporting To ExcelXml Publisher And Reporting To Excel
Xml Publisher And Reporting To ExcelDuncan Davies
 
Web services - A Practical Approach
Web services - A Practical ApproachWeb services - A Practical Approach
Web services - A Practical ApproachMadhaiyan Muthu
 
Introduction to RESTful Web Services
Introduction to RESTful Web ServicesIntroduction to RESTful Web Services
Introduction to RESTful Web ServicesFelipe Dornelas
 
Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013Mohan Arumugam
 

Tendances (20)

Crash course to the Apache Camel
Crash course to the Apache CamelCrash course to the Apache Camel
Crash course to the Apache Camel
 
JSON-RPC - JSON Remote Procedure Call
JSON-RPC - JSON Remote Procedure CallJSON-RPC - JSON Remote Procedure Call
JSON-RPC - JSON Remote Procedure Call
 
Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5
 
PHP and Web Services
PHP and Web ServicesPHP and Web Services
PHP and Web Services
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Wizard of ORDS
Wizard of ORDSWizard of ORDS
Wizard of ORDS
 
Tomcat Server
Tomcat ServerTomcat Server
Tomcat Server
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Reaching Out From PL/SQL (OPP 2010)
Reaching Out From PL/SQL (OPP 2010)Reaching Out From PL/SQL (OPP 2010)
Reaching Out From PL/SQL (OPP 2010)
 
The Functional Web
The Functional WebThe Functional Web
The Functional Web
 
Xml Publisher And Reporting To Excel
Xml Publisher And Reporting To ExcelXml Publisher And Reporting To Excel
Xml Publisher And Reporting To Excel
 
Web services - A Practical Approach
Web services - A Practical ApproachWeb services - A Practical Approach
Web services - A Practical Approach
 
Introduction to RESTful Web Services
Introduction to RESTful Web ServicesIntroduction to RESTful Web Services
Introduction to RESTful Web Services
 
Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Introduction to asp.net web api
Introduction to asp.net web apiIntroduction to asp.net web api
Introduction to asp.net web api
 

Similaire à Amsterdam php create a restful api

Cake fest 2012 create a restful api
Cake fest 2012 create a restful apiCake fest 2012 create a restful api
Cake fest 2012 create a restful apiceeram
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Nguyen Duc Phu
 
Intro to Hypermedia APIs
Intro to Hypermedia APIsIntro to Hypermedia APIs
Intro to Hypermedia APIsSmartLogic
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...ruyalarcon
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developersPatrick Savalle
 
Restful web services rule financial
Restful web services   rule financialRestful web services   rule financial
Restful web services rule financialRule_Financial
 
ITB2016 - Building ColdFusion RESTFul Services
ITB2016 - Building ColdFusion RESTFul ServicesITB2016 - Building ColdFusion RESTFul Services
ITB2016 - Building ColdFusion RESTFul ServicesOrtus Solutions, Corp
 
nguyenhainhathuy-building-restful-web-service
nguyenhainhathuy-building-restful-web-servicenguyenhainhathuy-building-restful-web-service
nguyenhainhathuy-building-restful-web-servicehazzaz
 
Great APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGreat APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGabriel Lucaciu
 
Introduction to REST and Hypermedia
Introduction to REST and HypermediaIntroduction to REST and Hypermedia
Introduction to REST and HypermediaNordic APIs
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsSagara Gunathunga
 
REST-API overview / concepts
REST-API overview / conceptsREST-API overview / concepts
REST-API overview / conceptsPatrick Savalle
 

Similaire à Amsterdam php create a restful api (20)

Cake fest 2012 create a restful api
Cake fest 2012 create a restful apiCake fest 2012 create a restful api
Cake fest 2012 create a restful api
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
 
Web api
Web apiWeb api
Web api
 
Intro to Hypermedia APIs
Intro to Hypermedia APIsIntro to Hypermedia APIs
Intro to Hypermedia APIs
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
Apex REST
Apex RESTApex REST
Apex REST
 
Restful web services rule financial
Restful web services   rule financialRestful web services   rule financial
Restful web services rule financial
 
ITB2016 - Building ColdFusion RESTFul Services
ITB2016 - Building ColdFusion RESTFul ServicesITB2016 - Building ColdFusion RESTFul Services
ITB2016 - Building ColdFusion RESTFul Services
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
L18 REST API Design
L18 REST API DesignL18 REST API Design
L18 REST API Design
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
 
nguyenhainhathuy-building-restful-web-service
nguyenhainhathuy-building-restful-web-servicenguyenhainhathuy-building-restful-web-service
nguyenhainhathuy-building-restful-web-service
 
Great APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGreat APIs - Future of Your Progress App
Great APIs - Future of Your Progress App
 
Introduction to REST and Hypermedia
Introduction to REST and HypermediaIntroduction to REST and Hypermedia
Introduction to REST and Hypermedia
 
HTTP Basics Demo
HTTP Basics DemoHTTP Basics Demo
HTTP Basics Demo
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
REST-API overview / concepts
REST-API overview / conceptsREST-API overview / concepts
REST-API overview / concepts
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Dernier

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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 Processorsdebabhi2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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 TerraformAndrey Devyatkin
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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 2024The Digital Insurer
 
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 Takeoffsammart93
 
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 DevelopmentsTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
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].pdfOverkill Security
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
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 Subbuapidays
 
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 WoodJuan lago vázquez
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Dernier (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
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
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Amsterdam php create a restful api

  • 1. AmsterdamPHP Create a RESTful api November 15, 2012 AmsterdamPHP
  • 2. INTRODUCTION Marc Ypes @Ceeram CakePHP 4 years Core team 1.5 years Undercover as programmer AmsterdamPHP
  • 3. OVERVIEW ■ Content-types ■ Interface ■ Authentication ■ Cache ■ Errors AmsterdamPHP
  • 4. INTRODUCTION TO REST Representational state transfer Set of architectural principles - resource focussed - manipulation through representations - HTTP protocol? AmsterdamPHP
  • 5. INTRODUCTION TO REST Constraints ■ Client-server ■ Stateless ■ Uniform interface ■ Cacheable ■ Layered system AmsterdamPHP
  • 6. INTRODUCTION TO REST Client-server separation of concerns portability of UI across platforms, scalability allowing components to evolve independently AmsterdamPHP
  • 7. INTRODUCTION TO REST Stateless request includes required information no stored context on server: Sessions AmsterdamPHP
  • 8. INTRODUCTION TO REST Uniform interface information is transfered in standardized form using nouns for resources (http) protocol describes methods AmsterdamPHP
  • 9. INTRODUCTION TO REST Cacheable reducing latency lower serverload AmsterdamPHP
  • 10. INTRODUCTION TO REST Layered system Server Client Proxy Gateway Security Anything AmsterdamPHP
  • 11. INTRODUCTION TO REST Uniform interface ■ resource ■ identification of the resource ■ manipulation through representation ■ self-descriptive ■ hypermedia as the engine of application state HATEOAS AmsterdamPHP
  • 12. INTRODUCTION TO REST Uniform Interface Data element Example resource user, book etc. (users, books etc.) resource identifier URL, URN (/users/1234) representation data TXT / HTML / XML /YAML,JSON metadata content type, last-modified time resource metadata source link, alternate control data if-modified-since, cache-control, etag http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm AmsterdamPHP
  • 13. INTRODUCTION TO REST Uniform Interface /api/getUserProfile/1234 /api/users?action=vote&id=1234 /api/deleteUser?id=1 AmsterdamPHP
  • 14. INTRODUCTION TO REST Uniform Interface RPC style Steep learning curve Documentation New functionality, BC AmsterdamPHP
  • 15. INTRODUCTION TO REST Uniform Interface 2 base urls - /books - /books/1234 AmsterdamPHP
  • 16. INTRODUCTION TO REST Uniform Interface GET /users Get collection POST /users Add to collection GET /users/1234 Get resource PUT /users/1234 Update resource DELETE /users/1234 Delete resource Update is not replace? POST /users/1234 AmsterdamPHP
  • 17. INTRODUCTION TO REST Uniform Interface Typical request: >GET /books/1849511926 HTTP/1.1 >Host: api.amazin.com >Accept: application/json >If-Modified-Since: Sat, 01 Sep 2012 10:22:36 GMT AmsterdamPHP
  • 18. INTRODUCTION TO REST Uniform Interface Typical response: < HTTP/1.1 200 OK < Date: Sat, 01 Sep 2012 11:45:12 GMT < Server: Apache/2.2.16 (Debian) < Last-Modified: Sat, 01 Sep 2012 11:25:31 GMT < Content-Length: 145 < Content-Type: application/json {"book":{........"}} AmsterdamPHP
  • 19. INTRODUCTION TO REST Uniform Interface Typical response: < HTTP/1.1 304 Not Modified < Date: Sat, 01 Sep 2012 11:45:12 GMT < Server: Apache/2.2.16 (Debian) < Vary: Accept-Encoding AmsterdamPHP
  • 20. INTRODUCTION TO REST Uniform Interface Safe methods Idempotent methods GET (HEAD) is safe (nullipotent) PUT, DELETE are idempotent POST PATCH? AmsterdamPHP
  • 21. INTRODUCTION TO REST Uniform Interface Normalize the resources GET /books/1849511926/votes GET /votes?book=1849511926 AmsterdamPHP
  • 22. INTRODUCTION TO REST Uniform Interface Normalize the resources POST /books/1849511926/votes PUT /books/1849511926 data contains votes subresource data POST /votes data is book=1849511926 AmsterdamPHP
  • 23. INTRODUCTION TO REST Uniform Interface PATCH Edge Rails: PATCH is the new primary HTTP method for updates http://weblog.rubyonrails.org/2012/2/25/edge-rails-patch-is-the-new-primary-http-method-for-updates/ AmsterdamPHP
  • 24. INTRODUCTION TO REST Versioning /rest /v1 content-type AmsterdamPHP
  • 25. INTRODUCTION TO REST Uniform Interface / HATEOAS Level 3 of REST maturity model (RMM) AmsterdamPHP
  • 26. INTRODUCTION TO REST Uniform Interface / HATEOAS Level 0 Single URI, single HTTP method AmsterdamPHP
  • 27. INTRODUCTION TO REST Uniform Interface / HATEOAS Level 1 Many URI, single HTTP method AmsterdamPHP
  • 28. INTRODUCTION TO REST Uniform Interface / HATEOAS Level 2 Many URI, different HTTP methods AmsterdamPHP
  • 29. INTRODUCTION TO REST Uniform Interface / HATEOAS Level 3 Self descriptive ■ Media types ■ Links ■ Other protocols AmsterdamPHP
  • 30. INTRODUCTION TO REST Uniform Interface / HATEOAS HATEOAS GET /comments?book=1849511926 Link to api.amazin.com/books/1849511926 Links to all comments AmsterdamPHP
  • 31. INTRODUCTION TO REST Uniform Interface / HATEOAS >GET /comments/1 <HTTP/1.1 200 Ok <Content-Type: text/xml <?xml version="1.0"> <comment> <foo>great book</foo> <book> <link href="/books/1849511926" title="wow" /> </book> </comment> AmsterdamPHP
  • 32. INTRODUCTION TO REST Uniform Interface / HATEOAS { "foo":"great book", "book": { "links":[ { "href":"/books/1849511926", "title":"wow" } ] } } AmsterdamPHP
  • 33. INTRODUCTION TO REST Uniform Interface / HATEOAS Link header Link: <https://api.github.com/user/repos?page=2&per_page=100>;rel=" next", <https://api.github.com/user/repos?page=50&per_page=100>;rel="last" github.com AmsterdamPHP
  • 34. INTRODUCTION TO REST Uniform Interface / Errors HTTP Statuscodes Human reads message Code reads code AmsterdamPHP
  • 35. INTRODUCTION TO REST Uniform Interface / Errors HTTP Statuscodes 200 OK 201 Created 204 No Content 304 Not Modified 400 Bad Request 401 Unauthorized 404 Not Found 405 Method Not Allowed AmsterdamPHP
  • 36. INTRODUCTION TO REST Uniform Interface / Errors Link to support page Link: <http://api.amazin.com/errors/405>; rel="help" AmsterdamPHP
  • 37. REST my Cake Authentication Public Api-key Basic Auth OAuth CakeFest 2012 Manchester
  • 38. INTRODUCTION TO REST Cacheable HTTP Cache headers Use them! AmsterdamPHP
  • 39. INTRODUCTION TO REST Cacheable HTTP Cache headers Cache-control - private - public - max-age / s-maxage - must-revalidate - nocache AmsterdamPHP
  • 40. INTRODUCTION TO REST Cacheable HTTP Cache validation Etag Response Last-Modified Response If-Modified-Since Request (GET) If-None-Match Request (GET) If-Match Request (PUT) AmsterdamPHP
  • 41. REST my Cake CakeResponse header( $header = NULL, $value = NULL ) send( ) statusCode( $code = NULL ) type( $contentType = NULL ) AmsterdamPHP
  • 42. REST my Cake CakeResponse cache( $since, $time = '+1 day' ) checkNotModified( $request ) disableCache( ) etag( $tag = NULL, $weak = false ) expires( $time = NULL ) maxAge( $seconds = NULL ) modified( $time = NULL ) mustRevalidate( $enable = NULL ) notModified( ) sharable( $public = NULL, $time = NULL ) sharedMaxAge( $seconds = NULL ) AmsterdamPHP
  • 43. REST my Cake CakePHP 3.0 2013 PHP 5.4 composer arrays => objects AmsterdamPHP
  • 44. INTRODUCTION TO REST REST might not be what you are looking for Questions? AmsterdamPHP
  • 45. INTRODUCTION TO REST THANKS https://joind.in/event/view/1141 AmsterdamPHP