Your SlideShare is downloading. ×
  • Like
  • Save
REST and Web API
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

REST and Web API



Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. IREST and Web APIRoman kalita_roman
  • 2. IWhy we need REST?Why speak about it?
  • 3. From web sites to web ApisFrom mobile to data
  • 4. RepresentationalStateTransfer 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
  • 5. Richardson Maturity Model I Level3: Hypermedia controls Level2: HTTP Verbs Level1: Resources Level0: POX, Single URI
  • 6. Level0POX, Single URI, Transport The systems focus are service end point URI and one HTTP verb (likely POST verb) for communication. AppointmentService GetOpenTimeSlot TimeSlotsList ServicClient e MakeAppointment ReservationResult
  • 7. Level1Resources Introduces resources, URIs per resource, but one HTTP ve Handling complexity by using divide and conquer, breaking a large endpoint down into multiple resources. POST doctors/eberwein Doctor s TimeSlotsListClient POST slots/15092012 Slots ReservationResult
  • 8. Level2 HTTP Verbs The system relies on more HTTP verbs and HTTP response codes on each resource. doctors/eberwein GET ?date=…&open=1 Doctor s 200 OK TimeSlotsListClient POST slots/15092012 Slots 204 CREATED ReservationResult
  • 9. Level3 Hypermedia Introduces discoverability, providing a way of making a protocol more self-documenting. 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
  • 10. 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
  • 11. Web API Routing  Routing “à la” ASP.NET MVC  Register your routs from Application_Start in Global.asax.csRouteTable.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)).)*$" });
  • 12. 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) {}}
  • 13. 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 querieshttp://localhost:38856/api/products?$filter=category+eq+Toys[Queryable]public IQueryable<Product> GetAllProducts(){ return repository.GetAll().AsQueryable();}
  • 14. 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
  • 15. Things that helpHTTP debugging proxies Fiddler Curl, for cmd-line fans Httpie, for cmd-line fans Wireshark Remote debugService things REST service help page Test web client
  • 16. Read more and references RFCs URI …/rfc3986.txt, URL …/rfc1738.txt HTTP, …/rfc2616.txt Web API bloggers  ASP.NET Web API   Alternatives to Web API  Martin Fowler’s article about Richardson Maturity Model  ml
  • 17.