SlideShare uma empresa Scribd logo
1 de 20
Pietro Libro
Applicazioni RESTful con ASP.NET Web API


pietro.libro@domusdotnet.org – DomusDotNet
Agenda
                Pietro Libro              pietro.libro@domusdotnetorg - DomusDotNet




   REST
   Web Api : SOAP & REST
   Web Api, definizione di un servizio
   Web Api Client
     Browser + JQuery
     Win 8 App Store
 Web Api Security
 Web Api Help Page
 Web Api Dependency Resolver
REST (Representational State Transfer)
                 Pietro Libro                   pietro.libro@domusdotnetorg - DomusDotNet




Da Wikipedia


«Representational state transfer (REST) è un tipo di architettura
software per i sistemi di ipertesto distribuiti come il World Wide Web. I
termini "representational state transfer" e "REST" furono introdotti
nel 2000 nella tesi di dottorato di Roy Fielding, uno dei principali
autori delle specifiche dell'Hypertext Transfer Protocol (HTTP),
termine ampiamente usato nella comunità di Internet»
REST (Representational State Transfer)
                Pietro Libro                pietro.libro@domusdotnetorg - DomusDotNet




REST prevede:
   Stato e funzionalità divise in Risorse
   Una Risorsa é unicamente indirizzabile tramite una sintassi
    universale (URI)
   Le Risorse sono condivise come interfaccia uniforme per il
    trasferimento di stato tra client e Risorse (operazioni &
    contenuti vincolati)
   Si basa su un protocollo:
        Client-Server
        Stateless
        Cachable
        A livelli
  I sistemi che seguono i principi REST sono definiti "RESTful".
REST (Representational State Transfer)
                Pietro Libro                  pietro.libro@domusdotnetorg - DomusDotNet




 REST: Risorsa
    Le risorse sono accessibili tramite i metodi propri HTTP
    ROA (Resource Oriented Architecture)
    Utilizza HTTP a livello applicativo
    Esalta il Web come piattaforma per l’elaborazione distribuita
    Nessua definizione delle interfacce di servizio tipo WSDL
 SOAP: Servizio
    Metodi -> RPC
    SOA (Service Oriented Architecture)
    HTTP a livello di trasporto, trasport multiprotocollo
    WSDL
REST (Representational State Transfer)
                Pietro Libro                 pietro.libro@domusdotnetorg - DomusDotNet




 REST: Risorsa
    Formato dati non fortemente tipizzato
    Diversi formati di rappresentazione (ad esempio JSON)
    Consumo dei servizi da qualsiasi piattaforma
 SOAP: Servizio
    Forte tipizzazione dei dati aderenti ad uno schema
    Formato dati XML
    Supporto a Sessioni, Routing e Transazioni
Web API Client
               Pietro Libro               pietro.libro@domusdotnetorg - DomusDotNet




 Web Browser + Jquery
 Applicazioni Web
    ASP.NET
    PHP
    ...
 Applicazioni Windows
    WPF (Windows Presentation Foundation)
    Windows 8 App Store
    Windows Form
 Dispositivi Mobile
 Praticamente uutti i client che hanno «accesso» al protocollo
  HTTP
Toolbox
               Pietro Libro               pietro.libro@domusdotnetorg - DomusDotNet




 .NET Framework 4.5
    Visual Studio 2012
    Visual Studio Express 2012 for Web


 .NET Framework 4.0
    Visual Studio 2010 con ASP.NET MVC 4
    Visual Studio 2010 Developer Express con ASP.NET MVC 4


 Installazione tramite Web Platform Installer
    http://www.microsoft.com/web/downloads/platform.aspx
ASP.NET Web Api
Pietro Libro      pietro.libro@domusdotnetorg - DomusDotNet




                                        DEMO
Web API Security
               Pietro Libro                pietro.libro@domusdotnetorg - DomusDotNet




 RESTful è Stateless
   Nessuna assunzione tra un’invocazione ed un’altra, sono
    completamente indipendenti
   Autenticazioneautorizzazione ad ogni richiesta
   HTTPHTTPS
 Come per ASP.NET MVC, «Controller» ed «Action»
  supportano:
   «[Authorize]»
   «[AllowAnonymous]»
Web API Security
               Pietro Libro                  pietro.libro@domusdotnetorg - DomusDotNet




 Message Handler
   Riceve una richiesta HTTP e ritorna una riposta HTTP


 I Message Handler possono lavorare in catena
   Adatti per cross-cutting concerns (ad esempio Security) a livello
    HTTP


 Un Message Handler può
   Leggere e modificare una richiesta
   Aggiungere Header ad una risposta
   Validare una richiesta prima che raggiunga un controller
Web API Security
Pietro Libro       pietro.libro@domusdotnetorg - DomusDotNet
Web API Security
Pietro Libro       pietro.libro@domusdotnetorg - DomusDotNet




                                         DEMO
Web API Dependency Resolver
                Pietro Libro                         pietro.libro@domusdotnetorg - DomusDotNet




 Dipendenza
  «Oggetto o interfaccia che un oggetto richiede per svolgere il
  proprio lavoro»


 Web API dependency resolver
  Permette di «iniettare» le dipendenze richieste da un ASP.NET
   Web Api Controller
      Un oggetto non è più responsabile di creare da se le dipendenze di cui
       necessità
      Le dipendenze necessarie verranno fornite da «qualcuno» dall’esterno
Dependency Resolver
Pietro Libro          pietro.libro@domusdotnetorg - DomusDotNet




                                            DEMO
Web API Help Page
            Pietro Libro         pietro.libro@domusdotnetorg - DomusDotNet




 Documentazione delle Web Api
  Automatica (via NuGet)
  Personalizzabile
  GUI
  IDocumentationProvider
Web API Help Page
Pietro Libro        pietro.libro@domusdotnetorg - DomusDotNet




                                          DEMO
Cosa non abbiamo visto
             Pietro Libro             pietro.libro@domusdotnetorg - DomusDotNet




 Media Type Formatters

 Content Negotation

 Testing, Debugging & Tracing

 OData & Web API
Riferimenti
               Pietro Libro      pietro.libro@domusdotnetorg - DomusDotNet




 ASP.NET
   http://www.asp.net/

 ASP.NET Web API
   http://www.asp.net/web-api

   Tutorial

   Video

   Esempi
Domande
Pietro Libro   pietro.libro@domusdotnetorg - DomusDotNet

Mais conteúdo relacionado

Semelhante a Applicazioni RESTful con ASP.NET Web Api

Self hosted Services with .NET OWin
Self hosted Services with .NET OWinSelf hosted Services with .NET OWin
Self hosted Services with .NET OWinNicolò Carandini
 
DomusDotNet, DotNetCode & dotNET{podcast} Meetup - Serverless Computing - Gio...
DomusDotNet, DotNetCode & dotNET{podcast} Meetup - Serverless Computing - Gio...DomusDotNet, DotNetCode & dotNET{podcast} Meetup - Serverless Computing - Gio...
DomusDotNet, DotNetCode & dotNET{podcast} Meetup - Serverless Computing - Gio...Codemotion
 
ASP.NET AND Azure Function
ASP.NET AND Azure FunctionASP.NET AND Azure Function
ASP.NET AND Azure FunctionLuca Congiu
 
5. Applicazioni Web e CMS
5. Applicazioni Web e CMS5. Applicazioni Web e CMS
5. Applicazioni Web e CMSRoberto Polillo
 
MS Days 08 Applicazioni RIA con Silverlight 2 e WCF
MS Days 08 Applicazioni RIA con Silverlight 2 e WCFMS Days 08 Applicazioni RIA con Silverlight 2 e WCF
MS Days 08 Applicazioni RIA con Silverlight 2 e WCFFabrizio Bernabei
 
Sviluppo di servizi REST per Android - Luca Masini
Sviluppo di servizi REST per Android - Luca Masini Sviluppo di servizi REST per Android - Luca Masini
Sviluppo di servizi REST per Android - Luca Masini Whymca
 
SVILUPPO DI SERVIZI REST PER ANDROID
SVILUPPO DI SERVIZI REST PER ANDROIDSVILUPPO DI SERVIZI REST PER ANDROID
SVILUPPO DI SERVIZI REST PER ANDROIDLuca Masini
 
Hands on MVC - Mastering the Web
Hands on MVC - Mastering the WebHands on MVC - Mastering the Web
Hands on MVC - Mastering the WebClaudio Gandelli
 
Esposizione RIA
Esposizione RIAEsposizione RIA
Esposizione RIAdiodorato
 
Web Project - LESSON 1
Web Project - LESSON 1Web Project - LESSON 1
Web Project - LESSON 1Yunikon Design
 
Applicazioni web con ASP.NET Owin e Katana
Applicazioni web con ASP.NET Owin e KatanaApplicazioni web con ASP.NET Owin e Katana
Applicazioni web con ASP.NET Owin e KatanaNicolò Carandini
 
Infrastrutture web e Ruby on Rails
Infrastrutture web e Ruby on RailsInfrastrutture web e Ruby on Rails
Infrastrutture web e Ruby on Railsguestfe3e15
 

Semelhante a Applicazioni RESTful con ASP.NET Web Api (20)

Self hosted Services with .NET OWin
Self hosted Services with .NET OWinSelf hosted Services with .NET OWin
Self hosted Services with .NET OWin
 
DomusDotNet, DotNetCode & dotNET{podcast} Meetup - Serverless Computing - Gio...
DomusDotNet, DotNetCode & dotNET{podcast} Meetup - Serverless Computing - Gio...DomusDotNet, DotNetCode & dotNET{podcast} Meetup - Serverless Computing - Gio...
DomusDotNet, DotNetCode & dotNET{podcast} Meetup - Serverless Computing - Gio...
 
ASP.NET AND Azure Function
ASP.NET AND Azure FunctionASP.NET AND Azure Function
ASP.NET AND Azure Function
 
8. Architetture web
8. Architetture web8. Architetture web
8. Architetture web
 
5. Applicazioni Web e CMS
5. Applicazioni Web e CMS5. Applicazioni Web e CMS
5. Applicazioni Web e CMS
 
Corso di servlet jsp e pattern
Corso di servlet jsp e patternCorso di servlet jsp e pattern
Corso di servlet jsp e pattern
 
Novità di Asp.Net 4.0
Novità di Asp.Net 4.0Novità di Asp.Net 4.0
Novità di Asp.Net 4.0
 
Swagger pertutti
Swagger pertuttiSwagger pertutti
Swagger pertutti
 
MS Days 08 Applicazioni RIA con Silverlight 2 e WCF
MS Days 08 Applicazioni RIA con Silverlight 2 e WCFMS Days 08 Applicazioni RIA con Silverlight 2 e WCF
MS Days 08 Applicazioni RIA con Silverlight 2 e WCF
 
Sviluppo di servizi REST per Android - Luca Masini
Sviluppo di servizi REST per Android - Luca Masini Sviluppo di servizi REST per Android - Luca Masini
Sviluppo di servizi REST per Android - Luca Masini
 
SVILUPPO DI SERVIZI REST PER ANDROID
SVILUPPO DI SERVIZI REST PER ANDROIDSVILUPPO DI SERVIZI REST PER ANDROID
SVILUPPO DI SERVIZI REST PER ANDROID
 
Swagger per tutti
Swagger per tuttiSwagger per tutti
Swagger per tutti
 
Hands on MVC - Mastering the Web
Hands on MVC - Mastering the WebHands on MVC - Mastering the Web
Hands on MVC - Mastering the Web
 
Esposizione RIA
Esposizione RIAEsposizione RIA
Esposizione RIA
 
Web Project - LESSON 1
Web Project - LESSON 1Web Project - LESSON 1
Web Project - LESSON 1
 
Applicazioni web con ASP.NET Owin e Katana
Applicazioni web con ASP.NET Owin e KatanaApplicazioni web con ASP.NET Owin e Katana
Applicazioni web con ASP.NET Owin e Katana
 
Infrastrutture web e Ruby on Rails
Infrastrutture web e Ruby on RailsInfrastrutture web e Ruby on Rails
Infrastrutture web e Ruby on Rails
 
Wcf data services
Wcf data servicesWcf data services
Wcf data services
 
Composite Apps
Composite AppsComposite Apps
Composite Apps
 
Composite Application
Composite ApplicationComposite Application
Composite Application
 

Mais de Pietro Libro

.NET Core, ASP.NET Core e Linux per il Mobile
.NET Core, ASP.NET Core e Linux per il Mobile.NET Core, ASP.NET Core e Linux per il Mobile
.NET Core, ASP.NET Core e Linux per il MobilePietro Libro
 
Introduzione ai Coded UI Tests
Introduzione ai Coded UI TestsIntroduzione ai Coded UI Tests
Introduzione ai Coded UI TestsPietro Libro
 
Asp.net web api reloaded
Asp.net web api reloadedAsp.net web api reloaded
Asp.net web api reloadedPietro Libro
 
Visual Studio 2013 - A New kind In Town - ASP.NET Web Api 2
Visual Studio 2013 - A New kind In Town - ASP.NET Web Api 2Visual Studio 2013 - A New kind In Town - ASP.NET Web Api 2
Visual Studio 2013 - A New kind In Town - ASP.NET Web Api 2Pietro Libro
 
EF Real life - EF@Work
EF Real life - EF@WorkEF Real life - EF@Work
EF Real life - EF@WorkPietro Libro
 
EF 6.0 What's New - EF@Work
EF 6.0 What's New - EF@WorkEF 6.0 What's New - EF@Work
EF 6.0 What's New - EF@WorkPietro Libro
 

Mais de Pietro Libro (6)

.NET Core, ASP.NET Core e Linux per il Mobile
.NET Core, ASP.NET Core e Linux per il Mobile.NET Core, ASP.NET Core e Linux per il Mobile
.NET Core, ASP.NET Core e Linux per il Mobile
 
Introduzione ai Coded UI Tests
Introduzione ai Coded UI TestsIntroduzione ai Coded UI Tests
Introduzione ai Coded UI Tests
 
Asp.net web api reloaded
Asp.net web api reloadedAsp.net web api reloaded
Asp.net web api reloaded
 
Visual Studio 2013 - A New kind In Town - ASP.NET Web Api 2
Visual Studio 2013 - A New kind In Town - ASP.NET Web Api 2Visual Studio 2013 - A New kind In Town - ASP.NET Web Api 2
Visual Studio 2013 - A New kind In Town - ASP.NET Web Api 2
 
EF Real life - EF@Work
EF Real life - EF@WorkEF Real life - EF@Work
EF Real life - EF@Work
 
EF 6.0 What's New - EF@Work
EF 6.0 What's New - EF@WorkEF 6.0 What's New - EF@Work
EF 6.0 What's New - EF@Work
 

Applicazioni RESTful con ASP.NET Web Api

  • 1. Pietro Libro Applicazioni RESTful con ASP.NET Web API pietro.libro@domusdotnet.org – DomusDotNet
  • 2. Agenda Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  REST  Web Api : SOAP & REST  Web Api, definizione di un servizio  Web Api Client  Browser + JQuery  Win 8 App Store  Web Api Security  Web Api Help Page  Web Api Dependency Resolver
  • 3. REST (Representational State Transfer) Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet Da Wikipedia «Representational state transfer (REST) è un tipo di architettura software per i sistemi di ipertesto distribuiti come il World Wide Web. I termini "representational state transfer" e "REST" furono introdotti nel 2000 nella tesi di dottorato di Roy Fielding, uno dei principali autori delle specifiche dell'Hypertext Transfer Protocol (HTTP), termine ampiamente usato nella comunità di Internet»
  • 4. REST (Representational State Transfer) Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet REST prevede:  Stato e funzionalità divise in Risorse  Una Risorsa é unicamente indirizzabile tramite una sintassi universale (URI)  Le Risorse sono condivise come interfaccia uniforme per il trasferimento di stato tra client e Risorse (operazioni & contenuti vincolati)  Si basa su un protocollo:  Client-Server  Stateless  Cachable  A livelli I sistemi che seguono i principi REST sono definiti "RESTful".
  • 5. REST (Representational State Transfer) Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  REST: Risorsa  Le risorse sono accessibili tramite i metodi propri HTTP  ROA (Resource Oriented Architecture)  Utilizza HTTP a livello applicativo  Esalta il Web come piattaforma per l’elaborazione distribuita  Nessua definizione delle interfacce di servizio tipo WSDL  SOAP: Servizio  Metodi -> RPC  SOA (Service Oriented Architecture)  HTTP a livello di trasporto, trasport multiprotocollo  WSDL
  • 6. REST (Representational State Transfer) Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  REST: Risorsa  Formato dati non fortemente tipizzato  Diversi formati di rappresentazione (ad esempio JSON)  Consumo dei servizi da qualsiasi piattaforma  SOAP: Servizio  Forte tipizzazione dei dati aderenti ad uno schema  Formato dati XML  Supporto a Sessioni, Routing e Transazioni
  • 7. Web API Client Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  Web Browser + Jquery  Applicazioni Web  ASP.NET  PHP  ...  Applicazioni Windows  WPF (Windows Presentation Foundation)  Windows 8 App Store  Windows Form  Dispositivi Mobile  Praticamente uutti i client che hanno «accesso» al protocollo HTTP
  • 8. Toolbox Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  .NET Framework 4.5  Visual Studio 2012  Visual Studio Express 2012 for Web  .NET Framework 4.0  Visual Studio 2010 con ASP.NET MVC 4  Visual Studio 2010 Developer Express con ASP.NET MVC 4  Installazione tramite Web Platform Installer  http://www.microsoft.com/web/downloads/platform.aspx
  • 9. ASP.NET Web Api Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet DEMO
  • 10. Web API Security Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  RESTful è Stateless  Nessuna assunzione tra un’invocazione ed un’altra, sono completamente indipendenti  Autenticazioneautorizzazione ad ogni richiesta  HTTPHTTPS  Come per ASP.NET MVC, «Controller» ed «Action» supportano:  «[Authorize]»  «[AllowAnonymous]»
  • 11. Web API Security Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  Message Handler  Riceve una richiesta HTTP e ritorna una riposta HTTP  I Message Handler possono lavorare in catena  Adatti per cross-cutting concerns (ad esempio Security) a livello HTTP  Un Message Handler può  Leggere e modificare una richiesta  Aggiungere Header ad una risposta  Validare una richiesta prima che raggiunga un controller
  • 12. Web API Security Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet
  • 13. Web API Security Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet DEMO
  • 14. Web API Dependency Resolver Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  Dipendenza  «Oggetto o interfaccia che un oggetto richiede per svolgere il proprio lavoro»  Web API dependency resolver  Permette di «iniettare» le dipendenze richieste da un ASP.NET Web Api Controller  Un oggetto non è più responsabile di creare da se le dipendenze di cui necessità  Le dipendenze necessarie verranno fornite da «qualcuno» dall’esterno
  • 15. Dependency Resolver Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet DEMO
  • 16. Web API Help Page Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  Documentazione delle Web Api  Automatica (via NuGet)  Personalizzabile  GUI  IDocumentationProvider
  • 17. Web API Help Page Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet DEMO
  • 18. Cosa non abbiamo visto Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  Media Type Formatters  Content Negotation  Testing, Debugging & Tracing  OData & Web API
  • 19. Riferimenti Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet  ASP.NET  http://www.asp.net/  ASP.NET Web API  http://www.asp.net/web-api  Tutorial  Video  Esempi
  • 20. Domande Pietro Libro pietro.libro@domusdotnetorg - DomusDotNet