SlideShare una empresa de Scribd logo
1 de 18
I
REST and Web API


Roman Kalita
kalita.roman@gmail.com
@rkregfor
Skype: kalita_roman
I
Why we need REST?
Why speak about it?
From web sites to web Apis
From mobile to data
Representational
State
Transfer
 Architectural style
  based on HTTP protocol usage and
  principles of The Web
 Tightly coupled to HTTP protocol
 Lightweight
 Stateless
 Simple caching “from the box”
 Easy to consume (e.g. mobile devices, JavaScript etc.)
 Goal: scaling, loose coupling and
  compose functionality across service boundaries
Richardson Maturity Model
                            I
 Level3: Hypermedia
 controls

 Level2: HTTP Verbs

 Level1: Resources

 Level0: POX, Single URI
Level0
POX, Single URI, Transport
 The systems focus are service end point URI and
  one HTTP verb (likely POST verb) for communication.


                                AppointmentService
                         GetOpenTimeSlot

                            TimeSlotsList
                                                Servic
Client
                                                  e
                         MakeAppointment

                            ReservationResult
Level1
Resources
 Introduces resources, URIs per resource, but one HTTP ve
 Handling complexity by using divide and conquer,
  breaking a large endpoint down into multiple resources.

                                            http://klinik.com/
         POST            doctors/eberwein       Doctor
                                                  s
                            TimeSlotsList
Client
         POST            slots/15092012
                                                Slots
                            ReservationResult
Level2
 HTTP Verbs

 The system relies on more HTTP verbs and
  HTTP response codes on each resource.


                                            http://klinik.com/
                        doctors/eberwein
         GET            ?date=…&open=1 Doctor
                                         s
                         200 OK TimeSlotsList
Client
         POST            slots/15092012
                                                 Slots
                 204 CREATED ReservationResult
Level3
 Hypermedia

 Introduces discoverability, providing a way of making
  a protocol more self-documenting.
                                                         http://klinik.com/
                            doctors/eberwein
         GET                ?date=…&open=1 Doctor
                           200 OK TimeSlotsList
                                                s
                     <link rel = "/linkrels/slot/book"
Client                      uri = "/slots/5678"/>


         POST                slots/15092012                 Slots

                   204 CREATED ReservationResult
Cooking REST on .NET –
 Web API
 URL Routing to produce clean URLs

 Content Negotiation based on Accept headers
  for request and response serialization

 Support for a host of supported output formats
  including JSON, XML, ATOM

 Extensible (easy to add new formats, custom handlers,
  routing, error handlers)

 Self-hostable in non-Web applications

 Testable using testing concepts similar to MVC
Web API Routing
   Routing “à la” ASP.NET MVC
   Register your routs from Application_Start in Global.asax.cs
RouteTable.Routes.MapHttpRoute(
  name: "UploadDownlaodOnlyTrhougthTransport",
  routeTemplate: "api/transports/{controller}/{id}",
  defaults: new { id = RouteParameter.Optional },
  constraints: new { controller = "uploads|downloads" }
);

RouteTable.Routes.MapHttpRoute(
  name: "AllExceptUploadaDownload",
  routeTemplate: "api/{controller}/{id}",
  defaults: new { id = RouteParameter.Optional },
  constraints:
    new { controller = @"^((?!(downloads|uploads)).)*$" }
);
Web API Controller
     Derived from ApiController
     Actions are mapped to URIs
      via naming convention or attributes
     Deep support for more advanced HTTP features
      via HttpResponseMessage and HttpRequestMessage.
public class ProductsController : ApiController
{
  public IEnumerable<Product> GetAllProducts(){}
  public Product GetProduct(int id) {}
  public HttpResponseMessage PostProduct(Product item) {}
  public void PutProduct(int id, Product contact) {}

    [AcceptVerbs("GET", "HEAD")]
    public Product FindProduct(id) {}
    [HttpGet]
    public Product FindProduct(id) {}
}
OData support
 Support “in the box” for OData $top, $skip, $filter, $orderby,
  advanced support in pre-release
  Install-Package Microsoft.AspNet.WebApi.OData -Pre

  Till release - as alternative use of WCF Data Services
 Queryable attribute to enable OData queries


http://localhost:38856/api/products?$filter=category+eq+'Toys'
[Queryable]
public IQueryable<Product> GetAllProducts()
{
  return repository.GetAll().AsQueryable();
}
Web API extensiblity
 Message handlers
  to handle request and responses

 Action filters
  for custom logic before and after action execution

 Custom formatters
  to add custom media type formats

 Dependency resolver
  to enable dependency injection for controllers
Things that help
HTTP debugging proxies
 Fiddler
  fiddler2.com
 Curl, for cmd-line fans
  curl.haxx.se
 Httpie, for cmd-line fans
  github.com/jkbr/httpie

Debugging
 Wireshark
 Remote debug

Service things
 REST service help page
 Test web client
Read more and references
 RFCs ietf.org/rfc/... URI …/rfc3986.txt,
  URL …/rfc1738.txt HTTP, …/rfc2616.txt

 Web API bloggers
   webapibloggers.com

 ASP.NET Web API
    asp.net/webapi
    aspnetwebstack.codeplex.com

 Alternatives to Web API
    servicestack.net

 Martin Fowler’s article about Richardson Maturity Model
   martinfowler.com/articles/richardsonMaturityModel.ht
    ml
http://www.flickr.com/photos/f-oxymoron/5005673112

Más contenido relacionado

La actualidad más candente

RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with JerseyScott Leberknight
 
RESTful Web Services in Drupal7
RESTful Web Services in Drupal7RESTful Web Services in Drupal7
RESTful Web Services in Drupal7bmeme
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座Li Yi
 
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 APIEyal Vardi
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraintInviqa
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servletssbd6985
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8Andrei Jechiu
 
Your rest api using laravel
Your rest api using laravelYour rest api using laravel
Your rest api using laravelSulaeman .
 
Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Jonathan LeBlanc
 
5. web api 2 aspdotnet-mvc5-slides
5. web api 2 aspdotnet-mvc5-slides5. web api 2 aspdotnet-mvc5-slides
5. web api 2 aspdotnet-mvc5-slidesMasterCode.vn
 
Restful webservice
Restful webserviceRestful webservice
Restful webserviceDong Ngoc
 

La actualidad más candente (20)

Mule caching strategy with redis cache
Mule caching strategy with redis cacheMule caching strategy with redis cache
Mule caching strategy with redis cache
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
 
Psr 7 symfony-day
Psr 7 symfony-dayPsr 7 symfony-day
Psr 7 symfony-day
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 
ASP.NET WEB API
ASP.NET WEB APIASP.NET WEB API
ASP.NET WEB API
 
RESTful Web Services in Drupal7
RESTful Web Services in Drupal7RESTful Web Services in Drupal7
RESTful Web Services in Drupal7
 
Rest web services
Rest web servicesRest web services
Rest web services
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
Soap and Rest
Soap and RestSoap and Rest
Soap and Rest
 
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
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraint
 
Message enricher in mule
Message enricher in muleMessage enricher in mule
Message enricher in mule
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8
 
Your rest api using laravel
Your rest api using laravelYour rest api using laravel
Your rest api using laravel
 
Security in php
Security in phpSecurity in php
Security in php
 
Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2
 
5. web api 2 aspdotnet-mvc5-slides
5. web api 2 aspdotnet-mvc5-slides5. web api 2 aspdotnet-mvc5-slides
5. web api 2 aspdotnet-mvc5-slides
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 

Destacado

Parallelism в .net 4 и vs2010
Parallelism в .net 4 и vs2010Parallelism в .net 4 и vs2010
Parallelism в .net 4 и vs2010Roman Kalita
 
Качество кода. NDepend
Качество кода. NDependКачество кода. NDepend
Качество кода. NDependRoman Kalita
 
SageCRM V7 Presentation
SageCRM V7 PresentationSageCRM V7 Presentation
SageCRM V7 Presentationjohn_allen
 
Iuavcamp presentazione
Iuavcamp presentazioneIuavcamp presentazione
Iuavcamp presentazionesilvia
 
Internet explorer 9 для разработчиков
Internet explorer 9 для разработчиковInternet explorer 9 для разработчиков
Internet explorer 9 для разработчиковRoman Kalita
 
Sage Accpacv5.6 Whats New
Sage Accpacv5.6 Whats NewSage Accpacv5.6 Whats New
Sage Accpacv5.6 Whats Newjohn_allen
 
Dependency injection на примере unity и n inject
Dependency injection на примере unity и n injectDependency injection на примере unity и n inject
Dependency injection на примере unity и n injectRoman Kalita
 
Iuavcamp presentazione
Iuavcamp presentazioneIuavcamp presentazione
Iuavcamp presentazionesilvia
 
Введение в Share point2010, ppt
Введение в Share point2010, pptВведение в Share point2010, ppt
Введение в Share point2010, pptRoman Kalita
 
Buzon contraloria1
Buzon contraloria1Buzon contraloria1
Buzon contraloria1Ricardo Rios
 
статические анализаторы кода за и против
статические анализаторы кода  за и противстатические анализаторы кода  за и против
статические анализаторы кода за и противRoman Kalita
 

Destacado (12)

Parallelism в .net 4 и vs2010
Parallelism в .net 4 и vs2010Parallelism в .net 4 и vs2010
Parallelism в .net 4 и vs2010
 
Качество кода. NDepend
Качество кода. NDependКачество кода. NDepend
Качество кода. NDepend
 
SageCRM V7 Presentation
SageCRM V7 PresentationSageCRM V7 Presentation
SageCRM V7 Presentation
 
Iuavcamp presentazione
Iuavcamp presentazioneIuavcamp presentazione
Iuavcamp presentazione
 
Internet explorer 9 для разработчиков
Internet explorer 9 для разработчиковInternet explorer 9 для разработчиков
Internet explorer 9 для разработчиков
 
Sage Accpacv5.6 Whats New
Sage Accpacv5.6 Whats NewSage Accpacv5.6 Whats New
Sage Accpacv5.6 Whats New
 
Dependency injection на примере unity и n inject
Dependency injection на примере unity и n injectDependency injection на примере unity и n inject
Dependency injection на примере unity и n inject
 
Iuavcamp presentazione
Iuavcamp presentazioneIuavcamp presentazione
Iuavcamp presentazione
 
N depend & cql
N depend & cqlN depend & cql
N depend & cql
 
Введение в Share point2010, ppt
Введение в Share point2010, pptВведение в Share point2010, ppt
Введение в Share point2010, ppt
 
Buzon contraloria1
Buzon contraloria1Buzon contraloria1
Buzon contraloria1
 
статические анализаторы кода за и против
статические анализаторы кода  за и противстатические анализаторы кода  за и против
статические анализаторы кода за и против
 

Similar a REST and Web API

Rest in practice
Rest in practiceRest in practice
Rest in practiceGabor Torok
 
Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applicationsSatish b
 
Rest presentation
Rest  presentationRest  presentation
Rest presentationsrividhyau
 
Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Tim Burks
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
Time to REST: testing web services
Time to REST: testing web servicesTime to REST: testing web services
Time to REST: testing web servicesIurii Kutelmakh
 
Automated testing web services - part 1
Automated testing web services - part 1Automated testing web services - part 1
Automated testing web services - part 1Aleh Struneuski
 
Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swiftTim Burks
 
01. http basics v27
01. http basics v2701. http basics v27
01. http basics v27Eoin Keary
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyPayal Jain
 
RESTful services
RESTful servicesRESTful services
RESTful servicesgouthamrv
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 

Similar a REST and Web API (20)

Rest in practice
Rest in practiceRest in practice
Rest in practice
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
 
Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
Doing REST Right
Doing REST RightDoing REST Right
Doing REST Right
 
Time to REST: testing web services
Time to REST: testing web servicesTime to REST: testing web services
Time to REST: testing web services
 
Automated testing web services - part 1
Automated testing web services - part 1Automated testing web services - part 1
Automated testing web services - part 1
 
Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swift
 
01. http basics v27
01. http basics v2701. http basics v27
01. http basics v27
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Why do you need REST
Why do you need RESTWhy do you need REST
Why do you need REST
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using Jersey
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Rest
RestRest
Rest
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 

Último

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 

REST and Web API

  • 1. I REST and Web API Roman Kalita kalita.roman@gmail.com @rkregfor Skype: kalita_roman
  • 2. I Why we need REST? Why speak about it?
  • 3.
  • 4. From web sites to web Apis From mobile to data
  • 5. Representational State Transfer  Architectural style based on HTTP protocol usage and principles of The Web  Tightly coupled to HTTP protocol  Lightweight  Stateless  Simple caching “from the box”  Easy to consume (e.g. mobile devices, JavaScript etc.)  Goal: scaling, loose coupling and compose functionality across service boundaries
  • 6. Richardson Maturity Model I Level3: Hypermedia controls Level2: HTTP Verbs Level1: Resources Level0: POX, Single URI
  • 7. Level0 POX, Single URI, Transport  The systems focus are service end point URI and one HTTP verb (likely POST verb) for communication. AppointmentService GetOpenTimeSlot TimeSlotsList Servic Client e MakeAppointment ReservationResult
  • 8. Level1 Resources  Introduces resources, URIs per resource, but one HTTP ve  Handling complexity by using divide and conquer, breaking a large endpoint down into multiple resources. http://klinik.com/ POST doctors/eberwein Doctor s TimeSlotsList Client POST slots/15092012 Slots ReservationResult
  • 9. Level2 HTTP Verbs  The system relies on more HTTP verbs and HTTP response codes on each resource. http://klinik.com/ doctors/eberwein GET ?date=…&open=1 Doctor s 200 OK TimeSlotsList Client POST slots/15092012 Slots 204 CREATED ReservationResult
  • 10. Level3 Hypermedia  Introduces discoverability, providing a way of making a protocol more self-documenting. http://klinik.com/ doctors/eberwein GET ?date=…&open=1 Doctor 200 OK TimeSlotsList s <link rel = "/linkrels/slot/book" Client uri = "/slots/5678"/> POST slots/15092012 Slots 204 CREATED ReservationResult
  • 11. Cooking REST on .NET – Web API  URL Routing to produce clean URLs  Content Negotiation based on Accept headers for request and response serialization  Support for a host of supported output formats including JSON, XML, ATOM  Extensible (easy to add new formats, custom handlers, routing, error handlers)  Self-hostable in non-Web applications  Testable using testing concepts similar to MVC
  • 12. Web API Routing  Routing “à la” ASP.NET MVC  Register your routs from Application_Start in Global.asax.cs RouteTable.Routes.MapHttpRoute( name: "UploadDownlaodOnlyTrhougthTransport", routeTemplate: "api/transports/{controller}/{id}", defaults: new { id = RouteParameter.Optional }, constraints: new { controller = "uploads|downloads" } ); RouteTable.Routes.MapHttpRoute( name: "AllExceptUploadaDownload", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }, constraints: new { controller = @"^((?!(downloads|uploads)).)*$" } );
  • 13. Web API Controller  Derived from ApiController  Actions are mapped to URIs via naming convention or attributes  Deep support for more advanced HTTP features via HttpResponseMessage and HttpRequestMessage. public class ProductsController : ApiController { public IEnumerable<Product> GetAllProducts(){} public Product GetProduct(int id) {} public HttpResponseMessage PostProduct(Product item) {} public void PutProduct(int id, Product contact) {} [AcceptVerbs("GET", "HEAD")] public Product FindProduct(id) {} [HttpGet] public Product FindProduct(id) {} }
  • 14. OData support  Support “in the box” for OData $top, $skip, $filter, $orderby, advanced support in pre-release Install-Package Microsoft.AspNet.WebApi.OData -Pre Till release - as alternative use of WCF Data Services  Queryable attribute to enable OData queries http://localhost:38856/api/products?$filter=category+eq+'Toys' [Queryable] public IQueryable<Product> GetAllProducts() { return repository.GetAll().AsQueryable(); }
  • 15. Web API extensiblity  Message handlers to handle request and responses  Action filters for custom logic before and after action execution  Custom formatters to add custom media type formats  Dependency resolver to enable dependency injection for controllers
  • 16. Things that help HTTP debugging proxies  Fiddler fiddler2.com  Curl, for cmd-line fans curl.haxx.se  Httpie, for cmd-line fans github.com/jkbr/httpie Debugging  Wireshark  Remote debug Service things  REST service help page  Test web client
  • 17. Read more and references  RFCs ietf.org/rfc/... URI …/rfc3986.txt, URL …/rfc1738.txt HTTP, …/rfc2616.txt  Web API bloggers  webapibloggers.com  ASP.NET Web API  asp.net/webapi  aspnetwebstack.codeplex.com  Alternatives to Web API  servicestack.net  Martin Fowler’s article about Richardson Maturity Model  martinfowler.com/articles/richardsonMaturityModel.ht ml