SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

RESTful Web Services in Drupal7
RESTful Web Services in Drupal7RESTful Web Services in Drupal7
RESTful Web Services in Drupal7
bmeme
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
Li Yi
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8
Andrei Jechiu
 

Tendances (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
 

En vedette (6)

Web development with ASP.NET Web API
Web development with ASP.NET Web APIWeb development with ASP.NET Web API
Web development with ASP.NET Web API
 
Windows Azure: Table Store, Service Bus Topics, Push Notifications & Notifica...
Windows Azure: Table Store, Service Bus Topics, Push Notifications & Notifica...Windows Azure: Table Store, Service Bus Topics, Push Notifications & Notifica...
Windows Azure: Table Store, Service Bus Topics, Push Notifications & Notifica...
 
WCF in .NET 4.0 - TVUG November 2010
WCF in .NET 4.0 - TVUG November 2010WCF in .NET 4.0 - TVUG November 2010
WCF in .NET 4.0 - TVUG November 2010
 
I've Got SaaSGrid: Now What? (1 of 2)
I've Got SaaSGrid: Now What? (1 of 2)I've Got SaaSGrid: Now What? (1 of 2)
I've Got SaaSGrid: Now What? (1 of 2)
 
ASP.NET MVC Web API
ASP.NET MVC Web APIASP.NET MVC Web API
ASP.NET MVC Web API
 
SaaSGrid: What's it good for? (2 of 2)
SaaSGrid: What's it good for? (2 of 2)SaaSGrid: What's it good for? (2 of 2)
SaaSGrid: What's it good for? (2 of 2)
 

Similaire à REST and Web API

Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
Satish b
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
srividhyau
 
RESTful services
RESTful servicesRESTful services
RESTful services
gouthamrv
 
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
Carol McDonald
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
Shreedhar Ganapathy
 

Similaire à 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 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
 
Rest
RestRest
Rest
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 

Plus de IT Weekend

Quality attributes testing. From Architecture to test acceptance
Quality attributes testing. From Architecture to test acceptanceQuality attributes testing. From Architecture to test acceptance
Quality attributes testing. From Architecture to test acceptance
IT Weekend
 
Как договариваться с начальником и заказчиком: выбираем нужный протокол общения
Как договариваться с начальником и заказчиком: выбираем нужный протокол общенияКак договариваться с начальником и заказчиком: выбираем нужный протокол общения
Как договариваться с начальником и заказчиком: выбираем нужный протокол общения
IT Weekend
 
Parallel programming in modern world .net technics shared
Parallel programming in modern world .net technics   sharedParallel programming in modern world .net technics   shared
Parallel programming in modern world .net technics shared
IT Weekend
 

Plus de IT Weekend (20)

Quality attributes testing. From Architecture to test acceptance
Quality attributes testing. From Architecture to test acceptanceQuality attributes testing. From Architecture to test acceptance
Quality attributes testing. From Architecture to test acceptance
 
Mobile development for JavaScript developer
Mobile development for JavaScript developerMobile development for JavaScript developer
Mobile development for JavaScript developer
 
Building an Innovation & Strategy Process
Building an Innovation & Strategy ProcessBuilding an Innovation & Strategy Process
Building an Innovation & Strategy Process
 
IT Professionals – The Right Time/The Right Place
IT Professionals – The Right Time/The Right PlaceIT Professionals – The Right Time/The Right Place
IT Professionals – The Right Time/The Right Place
 
Building a Data Driven Organization
Building a Data Driven OrganizationBuilding a Data Driven Organization
Building a Data Driven Organization
 
7 Tools for the Product Owner
7 Tools for the Product Owner 7 Tools for the Product Owner
7 Tools for the Product Owner
 
Hacking your Doorbell
Hacking your DoorbellHacking your Doorbell
Hacking your Doorbell
 
An era of possibilities, a window in time
An era of possibilities, a window in timeAn era of possibilities, a window in time
An era of possibilities, a window in time
 
Web services automation from sketch
Web services automation from sketchWeb services automation from sketch
Web services automation from sketch
 
Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
REST that won't make you cry
REST that won't make you cryREST that won't make you cry
REST that won't make you cry
 
Как договариваться с начальником и заказчиком: выбираем нужный протокол общения
Как договариваться с начальником и заказчиком: выбираем нужный протокол общенияКак договариваться с начальником и заказчиком: выбираем нужный протокол общения
Как договариваться с начальником и заказчиком: выбираем нужный протокол общения
 
Обзор программы SAP HANA Startup Focus
Обзор программы SAP HANA Startup FocusОбзор программы SAP HANA Startup Focus
Обзор программы SAP HANA Startup Focus
 
World of Agile: Kanban
World of Agile: KanbanWorld of Agile: Kanban
World of Agile: Kanban
 
Risk Management
Risk ManagementRisk Management
Risk Management
 
«Spring Integration as Integration Patterns Provider»
«Spring Integration as Integration Patterns Provider»«Spring Integration as Integration Patterns Provider»
«Spring Integration as Integration Patterns Provider»
 
Cutting edge of Machine Learning
Cutting edge of Machine LearningCutting edge of Machine Learning
Cutting edge of Machine Learning
 
Parallel Programming In Modern World .NET Technics
Parallel Programming In Modern World .NET TechnicsParallel Programming In Modern World .NET Technics
Parallel Programming In Modern World .NET Technics
 
Parallel programming in modern world .net technics shared
Parallel programming in modern world .net technics   sharedParallel programming in modern world .net technics   shared
Parallel programming in modern world .net technics shared
 
Maximize Effectiveness of Human Capital
Maximize Effectiveness of Human CapitalMaximize Effectiveness of Human Capital
Maximize Effectiveness of Human Capital
 

Dernier

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
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

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