SlideShare a Scribd company logo
I
REST and Web API


Roman Kalita
kalita.roman@gmail.com
@rkregfor
Skype: kalita_roman
I
Why we need REST?
Why speak about it?
REST and Web API
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

More Related Content

What's hot (20)

PDF
Mule caching strategy with redis cache
Priyobroto Ghosh (Mule ESB Certified)
 
PPTX
Restful web services ppt
OECLIB Odisha Electronics Control Library
 
PDF
RESTful Web Services with Jersey
Scott Leberknight
 
PDF
Psr 7 symfony-day
Marco Perone
 
PDF
SOAP-based Web Services
Katrien Verbert
 
PPTX
ASP.NET WEB API
Thang Chung
 
PDF
RESTful Web Services in Drupal7
bmeme
 
PDF
Rest web services
Paulo Gandra de Sousa
 
PPT
RESTful SOA - 中科院暑期讲座
Li Yi
 
PPT
Soap and Rest
Edison Lascano
 
PPTX
The Full Power of ASP.NET Web API
Eyal Vardi
 
KEY
Rest and the hypermedia constraint
Inviqa
 
PPTX
Message enricher in mule
Sashidhar Rao GDS
 
PPTX
UNIT-3 Servlet
ssbd6985
 
PDF
Services in Drupal 8
Andrei Jechiu
 
PDF
Your rest api using laravel
Sulaeman .
 
PDF
Security in php
Jalpesh Vasa
 
PPTX
Securing RESTful Payment APIs Using OAuth 2
Jonathan LeBlanc
 
PDF
5. web api 2 aspdotnet-mvc5-slides
MasterCode.vn
 
PPTX
Restful webservice
Dong Ngoc
 
Mule caching strategy with redis cache
Priyobroto Ghosh (Mule ESB Certified)
 
RESTful Web Services with Jersey
Scott Leberknight
 
Psr 7 symfony-day
Marco Perone
 
SOAP-based Web Services
Katrien Verbert
 
ASP.NET WEB API
Thang Chung
 
RESTful Web Services in Drupal7
bmeme
 
Rest web services
Paulo Gandra de Sousa
 
RESTful SOA - 中科院暑期讲座
Li Yi
 
Soap and Rest
Edison Lascano
 
The Full Power of ASP.NET Web API
Eyal Vardi
 
Rest and the hypermedia constraint
Inviqa
 
Message enricher in mule
Sashidhar Rao GDS
 
UNIT-3 Servlet
ssbd6985
 
Services in Drupal 8
Andrei Jechiu
 
Your rest api using laravel
Sulaeman .
 
Security in php
Jalpesh Vasa
 
Securing RESTful Payment APIs Using OAuth 2
Jonathan LeBlanc
 
5. web api 2 aspdotnet-mvc5-slides
MasterCode.vn
 
Restful webservice
Dong Ngoc
 

Viewers also liked (12)

PPTX
Parallelism в .net 4 и vs2010
Roman Kalita
 
PPTX
Качество кода. NDepend
Roman Kalita
 
PPT
SageCRM V7 Presentation
john_allen
 
ODP
Iuavcamp presentazione
silvia
 
PPTX
Internet explorer 9 для разработчиков
Roman Kalita
 
PPT
Sage Accpacv5.6 Whats New
john_allen
 
PPTX
Dependency injection на примере unity и n inject
Roman Kalita
 
ODP
Iuavcamp presentazione
silvia
 
PPT
N depend & cql
Roman Kalita
 
PPTX
Введение в Share point2010, ppt
Roman Kalita
 
PPT
Buzon contraloria1
Ricardo Rios
 
PPTX
статические анализаторы кода за и против
Roman Kalita
 
Parallelism в .net 4 и vs2010
Roman Kalita
 
Качество кода. NDepend
Roman Kalita
 
SageCRM V7 Presentation
john_allen
 
Iuavcamp presentazione
silvia
 
Internet explorer 9 для разработчиков
Roman Kalita
 
Sage Accpacv5.6 Whats New
john_allen
 
Dependency injection на примере unity и n inject
Roman Kalita
 
Iuavcamp presentazione
silvia
 
N depend & cql
Roman Kalita
 
Введение в Share point2010, ppt
Roman Kalita
 
Buzon contraloria1
Ricardo Rios
 
статические анализаторы кода за и против
Roman Kalita
 
Ad

Similar to REST and Web API (20)

PPTX
Rest in practice
Gabor Torok
 
PPTX
About REST. Архитектурные семинары Softengi
Softengi
 
PDF
What is REST?
Saeid Zebardast
 
PPTX
Best Practices for Architecting a Pragmatic Web API.
Mario Cardinal
 
PPTX
RESTful APIs in .NET
Greg Sohl
 
PPTX
Rest WebAPI with OData
Mahek Merchant
 
PDF
REST Api with Asp Core
Irina Scurtu
 
PPTX
Rest APIs Training
Shekhar Kumar
 
PDF
GlueCon 2018: Are REST APIs Still Relevant Today?
LaunchAny
 
PPTX
REST Methodologies
jrodbx
 
PDF
SOA with REST
Cesare Pautasso
 
PDF
Best Practice in Web Service Design
Lorna Mitchell
 
PPTX
RESTful Web Services
Gordon Dickens
 
KEY
I got 99 problems, but ReST ain't one
Adrian Cole
 
PPTX
Building Software Backend (Web API)
Alexander Goida
 
PDF
Together Cheerfully to Walk with Hypermedia
Vladimir Tsukur
 
PPTX
Creating Truly RESTful APIs
Domenic Denicola
 
PDF
Composing REST Services
elliando dias
 
PPTX
Soap UI and postman
Tushar Agarwal
 
PPTX
rest-api-basics.pptx
AgungSutikno1
 
Rest in practice
Gabor Torok
 
About REST. Архитектурные семинары Softengi
Softengi
 
What is REST?
Saeid Zebardast
 
Best Practices for Architecting a Pragmatic Web API.
Mario Cardinal
 
RESTful APIs in .NET
Greg Sohl
 
Rest WebAPI with OData
Mahek Merchant
 
REST Api with Asp Core
Irina Scurtu
 
Rest APIs Training
Shekhar Kumar
 
GlueCon 2018: Are REST APIs Still Relevant Today?
LaunchAny
 
REST Methodologies
jrodbx
 
SOA with REST
Cesare Pautasso
 
Best Practice in Web Service Design
Lorna Mitchell
 
RESTful Web Services
Gordon Dickens
 
I got 99 problems, but ReST ain't one
Adrian Cole
 
Building Software Backend (Web API)
Alexander Goida
 
Together Cheerfully to Walk with Hypermedia
Vladimir Tsukur
 
Creating Truly RESTful APIs
Domenic Denicola
 
Composing REST Services
elliando dias
 
Soap UI and postman
Tushar Agarwal
 
rest-api-basics.pptx
AgungSutikno1
 
Ad

Recently uploaded (20)

PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 

REST and Web API

  • 1. I REST and Web API Roman Kalita [email protected] @rkregfor Skype: kalita_roman
  • 2. I Why we need REST? Why speak about it?
  • 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