SlideShare une entreprise Scribd logo
1  sur  23
Maurice de Beijer
Waar gaan we het over hebben
 Wat zijn REST services
 Wat is de ASP.NET Web API
 Hoe kan je een REST service vanuit de browser
  gebruiken
 Realtime communicatie
Wie ben ik
 Maurice de Beijer.
 The Problem Solver.
 Microsoft CSD MVP.
 DevelopMentor instructor.
 Twitter:   @mauricedb of @HTML5SupportNL
 Blog:      http://msmvps.com/blogs/
             theproblemsolver/default.aspx
 Web:       http://www.HTML5Support.nl
 E-mail:    mauricedb@computer.org
Wat is REST
 Representational State Transfer
 REST is een architectuur voor gedistribueerde
  applicaties
 Er is geen REST standaard
 De HTTP standaard is de basis
   Heeft zich door de jaren bewezen
Hypertext Transfer Protocol

     The Hypertext Transfer Protocol (HTTP) is an
             application-level protocol for
  distributed, collaborative, hypermedia information
systems. It is a generic, stateless, protocol which can
  be used for many tasks beyond its use for hypertext
REST is niet nieuw
 Architectural Styles and the Design of Network-based
 Software Architectures
   By Roy Thomas Fielding
   Chapter 5
 Een van de schrijvers van de
 HTTP specificaties
Basis begrippen
 Resource = data
    Bv: een product of een klant
 Representation = het weergave formaat
    Bv: XML, JSON
    Maar ook een PDF of een vCard
REST versus SOAP
                    REST            SOAP
Standardized        No              WS-*
Transport           HTTP            HTTP, FTP, Pipes,
                                    MSMQ etc
Data Format         Any             XML
Reach               Very good       Good
Development tools   Basic           Good
Flexibility         Flexible        Rigid
Scalability         Very good       Reasonable
Security            HTTP Security   WS-Security
Operations          Stateless       Often statefull
ASP.NET Web API
 Onderdeel van ASP.NET MVC 4
    Maar ook los te gebruiken
    Zelfs buiten ASP.NET
 Gebruik ApiController als de baseclass
    Gewoon de data ipv een ActionResult teruggeven
 Routing net als normale controllers
    Alleen RouteCollection.MapHttpRoute() gebruiken
    De standaard route is: "api/{controller}/{id}"
HTTP Methods
 HTTP methods worden gebruikt om acties aan te
  geven
 ASP.NET Web API gebruikt functie namen
   Attributen kan eventueel ook

      Action                 HTTP Method
      Create                 POST
      Read                   GET
      Update (replace)       PUT
      Update (partial)       PATCH of MERGE
      Delete                 DELETE
HTTP Status Codes
 Een verplicht onderdeel van elke response
    Als alles goed gaat is het 200 OK
 Ingedeeld in groepen
    1-- Informational
    2-- Success
    3-- Redirection
    4-- Client Error
    5-- Server Error
 Binnen de ASP.NET Web API met een
  HttpResponseMessage aan te geven
   Anders is het 200 OK
Resource formats
 Web API ondersteunt content negotiation
    XML, JSON en Form Encoded standaard
 De client gebruikt de Accept header
    De server mag daar van afwijken!
 Extra formats toe te voegen via MediaTypeFormatter
Pauze
Browsers en REST
 Soms vergeet een browser de juiste Accept header
 HTML != HTTP
 Caching
Accept headers
 Sommige browsers claimen alles als image te kunnen
 t0nen
   De Accept header mist of bevat */*
 Via de URL aangeven wat het gewenste formaat is
    GET /api/books/1?$format=jpeg
 In de MediaTypeFormatter een
 AddQueryStringMapping () doen.
HTML != HTTP
 De HTTP standaard ondersteunt veel request methods
 als GET, PUT, POST, DELETE etc
   Maar de browser alleen GET en POST
 Gebruik het XMLHttpRequest
    Maar dan via jQuery.ajax()
Caching
 Caching maakt het web schaalbaar
    En kan ook helpen binnen onze applicaties
 Standaard wordt data niet gecached bij de Web API
    En dat is een goede zaak want browsers hebben
     verschillende defaults
 Caching is moeilijk goed te krijgen
    Caching instructies zijn alleen hints
Cross-origin resource sharing
 Een XmlHttpRequest mag alleen naar de
 oorspronkelijke server
   JSONP is een oplossing maar kan alleen GET
 CORS maakt het mogelijk om naar een andere server
 te gaan
   De service voegt een extra HTTP header toe
   Als die ontbreekt blokeert de browser de response
Real time communications
 Waarom wachten tot een gebruiker de pagina ververst?
    De server kan wijzigingen ook naar de browser sturen
 In HTML5 hebben we WebSockets
    Maar de ondersteuning is nog beperkt
 SignalR is een goede communicatie library
    Gebruikt WebSockets indien mogelijk
    Gebruikt anders een fallback communicatie
Conclusie
 REST services zijn zeer flexibel
    En dat is maar goed ook met alle tablets en smartphones
 De ASP.NET Web API is een prima framework
    En er zijn genoeg alternatieven
 Browsers hebben hun kuren
    Test met verschillende browsers
 Real time communicatie heeft de toekomst
Vragen ?
mauricedb@computer.org

Contenu connexe

Similaire à HTML5 & rest services

Rollbase via de REST adapter koppelen met OpenEdge
Rollbase via de REST adapter koppelen met OpenEdgeRollbase via de REST adapter koppelen met OpenEdge
Rollbase via de REST adapter koppelen met OpenEdgeJoris Kroes
 
Php samenvatting
Php samenvattingPhp samenvatting
Php samenvattingmvanginkel
 
Cursus Zend Framework - 1
Cursus Zend Framework - 1Cursus Zend Framework - 1
Cursus Zend Framework - 1bartjeukendrup
 
Webredactie Webrichtlijnen Deel1
Webredactie Webrichtlijnen Deel1Webredactie Webrichtlijnen Deel1
Webredactie Webrichtlijnen Deel1jaapvandeputte
 
Nord Toelichting Techniek
Nord Toelichting TechniekNord Toelichting Techniek
Nord Toelichting Techniektjercus
 
Ngn exchangemiddag
Ngn exchangemiddagNgn exchangemiddag
Ngn exchangemiddagjveldh
 
Naf LaC 2009 - Web 2.0 en Technologie
Naf LaC 2009 - Web 2.0 en TechnologieNaf LaC 2009 - Web 2.0 en Technologie
Naf LaC 2009 - Web 2.0 en TechnologieBram de Kruijff
 
DPC2007 Case Study Surfnet (Herman Van Dompseler)
DPC2007 Case Study Surfnet (Herman Van Dompseler)DPC2007 Case Study Surfnet (Herman Van Dompseler)
DPC2007 Case Study Surfnet (Herman Van Dompseler)dpc
 
Ict2 trm- werking internet
Ict2 trm- werking internetIct2 trm- werking internet
Ict2 trm- werking internetkaatversele
 
Business Process Execution Language (BPEL)
Business Process Execution Language (BPEL)Business Process Execution Language (BPEL)
Business Process Execution Language (BPEL)Richard Claassens CIPPE
 
Copernica programmeurstraining DMSummit 2010
Copernica programmeurstraining DMSummit 2010Copernica programmeurstraining DMSummit 2010
Copernica programmeurstraining DMSummit 2010Copernica BV
 
20111013 view point interactief - soap calls
20111013   view point interactief - soap calls20111013   view point interactief - soap calls
20111013 view point interactief - soap callsjwlogemann
 
Introductie robot framework
Introductie robot frameworkIntroductie robot framework
Introductie robot frameworkchristiantester
 
Third Generation Internet Applications
Third Generation Internet ApplicationsThird Generation Internet Applications
Third Generation Internet ApplicationsPatrick Koning
 
Toegankelijkheid
ToegankelijkheidToegankelijkheid
ToegankelijkheidAtticus
 

Similaire à HTML5 & rest services (20)

Api kooien les 1
Api kooien les 1Api kooien les 1
Api kooien les 1
 
Rollbase via de REST adapter koppelen met OpenEdge
Rollbase via de REST adapter koppelen met OpenEdgeRollbase via de REST adapter koppelen met OpenEdge
Rollbase via de REST adapter koppelen met OpenEdge
 
Php samenvatting
Php samenvattingPhp samenvatting
Php samenvatting
 
Cursus Zend Framework - 1
Cursus Zend Framework - 1Cursus Zend Framework - 1
Cursus Zend Framework - 1
 
Webredactie Webrichtlijnen Deel1
Webredactie Webrichtlijnen Deel1Webredactie Webrichtlijnen Deel1
Webredactie Webrichtlijnen Deel1
 
Modern web development
Modern web developmentModern web development
Modern web development
 
Nord Toelichting Techniek
Nord Toelichting TechniekNord Toelichting Techniek
Nord Toelichting Techniek
 
The Need For Speed
The Need For SpeedThe Need For Speed
The Need For Speed
 
Ngn exchangemiddag
Ngn exchangemiddagNgn exchangemiddag
Ngn exchangemiddag
 
Les 4 php w2
Les 4 php w2Les 4 php w2
Les 4 php w2
 
Naf LaC 2009 - Web 2.0 en Technologie
Naf LaC 2009 - Web 2.0 en TechnologieNaf LaC 2009 - Web 2.0 en Technologie
Naf LaC 2009 - Web 2.0 en Technologie
 
DPC2007 Case Study Surfnet (Herman Van Dompseler)
DPC2007 Case Study Surfnet (Herman Van Dompseler)DPC2007 Case Study Surfnet (Herman Van Dompseler)
DPC2007 Case Study Surfnet (Herman Van Dompseler)
 
QNH pizza sessie
QNH pizza sessieQNH pizza sessie
QNH pizza sessie
 
Ict2 trm- werking internet
Ict2 trm- werking internetIct2 trm- werking internet
Ict2 trm- werking internet
 
Business Process Execution Language (BPEL)
Business Process Execution Language (BPEL)Business Process Execution Language (BPEL)
Business Process Execution Language (BPEL)
 
Copernica programmeurstraining DMSummit 2010
Copernica programmeurstraining DMSummit 2010Copernica programmeurstraining DMSummit 2010
Copernica programmeurstraining DMSummit 2010
 
20111013 view point interactief - soap calls
20111013   view point interactief - soap calls20111013   view point interactief - soap calls
20111013 view point interactief - soap calls
 
Introductie robot framework
Introductie robot frameworkIntroductie robot framework
Introductie robot framework
 
Third Generation Internet Applications
Third Generation Internet ApplicationsThird Generation Internet Applications
Third Generation Internet Applications
 
Toegankelijkheid
ToegankelijkheidToegankelijkheid
Toegankelijkheid
 

Plus de Maurice De Beijer [MVP]

Practice TypeScript Techniques Building React Server Components App
Practice TypeScript Techniques Building React Server Components AppPractice TypeScript Techniques Building React Server Components App
Practice TypeScript Techniques Building React Server Components AppMaurice De Beijer [MVP]
 
A foolproof Way to Estimate a Software Project
A foolproof Way to Estimate a Software ProjectA foolproof Way to Estimate a Software Project
A foolproof Way to Estimate a Software ProjectMaurice De Beijer [MVP]
 
Surati Tech Talks 2022 / Build reliable Svelte applications using Cypress
Surati Tech Talks 2022 / Build reliable Svelte applications using CypressSurati Tech Talks 2022 / Build reliable Svelte applications using Cypress
Surati Tech Talks 2022 / Build reliable Svelte applications using CypressMaurice De Beijer [MVP]
 
Build reliable Svelte applications using Cypress
Build reliable Svelte applications using CypressBuild reliable Svelte applications using Cypress
Build reliable Svelte applications using CypressMaurice De Beijer [MVP]
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureMaurice De Beijer [MVP]
 
Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18Maurice De Beijer [MVP]
 
Building reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and AzureBuilding reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and AzureMaurice De Beijer [MVP]
 
Building large and scalable mission critical applications with React
Building large and scalable mission critical applications with ReactBuilding large and scalable mission critical applications with React
Building large and scalable mission critical applications with ReactMaurice De Beijer [MVP]
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureMaurice De Beijer [MVP]
 
Building reliable web applications using Cypress
Building reliable web applications using CypressBuilding reliable web applications using Cypress
Building reliable web applications using CypressMaurice De Beijer [MVP]
 
Getting started with React Suspense and concurrent rendering
Getting started with React Suspense and concurrent renderingGetting started with React Suspense and concurrent rendering
Getting started with React Suspense and concurrent renderingMaurice De Beijer [MVP]
 
React suspense, not just for Alfred Hitchcock
React suspense, not just for Alfred HitchcockReact suspense, not just for Alfred Hitchcock
React suspense, not just for Alfred HitchcockMaurice De Beijer [MVP]
 
From zero to hero with the Reactive extensions for JavaScript
From zero to hero with the Reactive extensions for JavaScriptFrom zero to hero with the Reactive extensions for JavaScript
From zero to hero with the Reactive extensions for JavaScriptMaurice De Beijer [MVP]
 
From zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScriptFrom zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScriptMaurice De Beijer [MVP]
 
Create flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apisCreate flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apisMaurice De Beijer [MVP]
 

Plus de Maurice De Beijer [MVP] (20)

Practice TypeScript Techniques Building React Server Components App
Practice TypeScript Techniques Building React Server Components AppPractice TypeScript Techniques Building React Server Components App
Practice TypeScript Techniques Building React Server Components App
 
A foolproof Way to Estimate a Software Project
A foolproof Way to Estimate a Software ProjectA foolproof Way to Estimate a Software Project
A foolproof Way to Estimate a Software Project
 
Surati Tech Talks 2022 / Build reliable Svelte applications using Cypress
Surati Tech Talks 2022 / Build reliable Svelte applications using CypressSurati Tech Talks 2022 / Build reliable Svelte applications using Cypress
Surati Tech Talks 2022 / Build reliable Svelte applications using Cypress
 
Build reliable Svelte applications using Cypress
Build reliable Svelte applications using CypressBuild reliable Svelte applications using Cypress
Build reliable Svelte applications using Cypress
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & Azure
 
Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18
 
Building reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and AzureBuilding reliable applications with React, C#, and Azure
Building reliable applications with React, C#, and Azure
 
Building large and scalable mission critical applications with React
Building large and scalable mission critical applications with ReactBuilding large and scalable mission critical applications with React
Building large and scalable mission critical applications with React
 
Building Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & AzureBuilding Reliable Applications Using React, .NET & Azure
Building Reliable Applications Using React, .NET & Azure
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
 
Building reliable web applications using Cypress
Building reliable web applications using CypressBuilding reliable web applications using Cypress
Building reliable web applications using Cypress
 
Getting started with React Suspense and concurrent rendering
Getting started with React Suspense and concurrent renderingGetting started with React Suspense and concurrent rendering
Getting started with React Suspense and concurrent rendering
 
React suspense, not just for Alfred Hitchcock
React suspense, not just for Alfred HitchcockReact suspense, not just for Alfred Hitchcock
React suspense, not just for Alfred Hitchcock
 
From zero to hero with the Reactive extensions for JavaScript
From zero to hero with the Reactive extensions for JavaScriptFrom zero to hero with the Reactive extensions for JavaScript
From zero to hero with the Reactive extensions for JavaScript
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
 
The new React
The new React The new React
The new React
 
From zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScriptFrom zero to hero with the reactive extensions for JavaScript
From zero to hero with the reactive extensions for JavaScript
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
 
I am hooked on React
I am hooked on ReactI am hooked on React
I am hooked on React
 
Create flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apisCreate flexible React applications using GraphQL apis
Create flexible React applications using GraphQL apis
 

HTML5 & rest services

  • 2. Waar gaan we het over hebben  Wat zijn REST services  Wat is de ASP.NET Web API  Hoe kan je een REST service vanuit de browser gebruiken  Realtime communicatie
  • 3. Wie ben ik  Maurice de Beijer.  The Problem Solver.  Microsoft CSD MVP.  DevelopMentor instructor.  Twitter: @mauricedb of @HTML5SupportNL  Blog: http://msmvps.com/blogs/ theproblemsolver/default.aspx  Web: http://www.HTML5Support.nl  E-mail: mauricedb@computer.org
  • 4. Wat is REST  Representational State Transfer  REST is een architectuur voor gedistribueerde applicaties  Er is geen REST standaard  De HTTP standaard is de basis  Heeft zich door de jaren bewezen
  • 5. Hypertext Transfer Protocol The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. It is a generic, stateless, protocol which can be used for many tasks beyond its use for hypertext
  • 6. REST is niet nieuw  Architectural Styles and the Design of Network-based Software Architectures  By Roy Thomas Fielding  Chapter 5  Een van de schrijvers van de HTTP specificaties
  • 7. Basis begrippen  Resource = data  Bv: een product of een klant  Representation = het weergave formaat  Bv: XML, JSON  Maar ook een PDF of een vCard
  • 8. REST versus SOAP REST SOAP Standardized No WS-* Transport HTTP HTTP, FTP, Pipes, MSMQ etc Data Format Any XML Reach Very good Good Development tools Basic Good Flexibility Flexible Rigid Scalability Very good Reasonable Security HTTP Security WS-Security Operations Stateless Often statefull
  • 9. ASP.NET Web API  Onderdeel van ASP.NET MVC 4  Maar ook los te gebruiken  Zelfs buiten ASP.NET  Gebruik ApiController als de baseclass  Gewoon de data ipv een ActionResult teruggeven  Routing net als normale controllers  Alleen RouteCollection.MapHttpRoute() gebruiken  De standaard route is: "api/{controller}/{id}"
  • 10. HTTP Methods  HTTP methods worden gebruikt om acties aan te geven  ASP.NET Web API gebruikt functie namen  Attributen kan eventueel ook Action HTTP Method Create POST Read GET Update (replace) PUT Update (partial) PATCH of MERGE Delete DELETE
  • 11. HTTP Status Codes  Een verplicht onderdeel van elke response  Als alles goed gaat is het 200 OK  Ingedeeld in groepen  1-- Informational  2-- Success  3-- Redirection  4-- Client Error  5-- Server Error  Binnen de ASP.NET Web API met een HttpResponseMessage aan te geven  Anders is het 200 OK
  • 12.
  • 13. Resource formats  Web API ondersteunt content negotiation  XML, JSON en Form Encoded standaard  De client gebruikt de Accept header  De server mag daar van afwijken!  Extra formats toe te voegen via MediaTypeFormatter
  • 14.
  • 15. Pauze
  • 16. Browsers en REST  Soms vergeet een browser de juiste Accept header  HTML != HTTP  Caching
  • 17. Accept headers  Sommige browsers claimen alles als image te kunnen t0nen  De Accept header mist of bevat */*  Via de URL aangeven wat het gewenste formaat is  GET /api/books/1?$format=jpeg  In de MediaTypeFormatter een AddQueryStringMapping () doen.
  • 18. HTML != HTTP  De HTTP standaard ondersteunt veel request methods als GET, PUT, POST, DELETE etc  Maar de browser alleen GET en POST  Gebruik het XMLHttpRequest  Maar dan via jQuery.ajax()
  • 19. Caching  Caching maakt het web schaalbaar  En kan ook helpen binnen onze applicaties  Standaard wordt data niet gecached bij de Web API  En dat is een goede zaak want browsers hebben verschillende defaults  Caching is moeilijk goed te krijgen  Caching instructies zijn alleen hints
  • 20. Cross-origin resource sharing  Een XmlHttpRequest mag alleen naar de oorspronkelijke server  JSONP is een oplossing maar kan alleen GET  CORS maakt het mogelijk om naar een andere server te gaan  De service voegt een extra HTTP header toe  Als die ontbreekt blokeert de browser de response
  • 21. Real time communications  Waarom wachten tot een gebruiker de pagina ververst?  De server kan wijzigingen ook naar de browser sturen  In HTML5 hebben we WebSockets  Maar de ondersteuning is nog beperkt  SignalR is een goede communicatie library  Gebruikt WebSockets indien mogelijk  Gebruikt anders een fallback communicatie
  • 22. Conclusie  REST services zijn zeer flexibel  En dat is maar goed ook met alle tablets en smartphones  De ASP.NET Web API is een prima framework  En er zijn genoeg alternatieven  Browsers hebben hun kuren  Test met verschillende browsers  Real time communicatie heeft de toekomst