SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 
статические анализаторы кода за и против
статические анализаторы кода  за и противстатические анализаторы кода  за и против
статические анализаторы кода за и против
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Kürzlich hochgeladen (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

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