SlideShare a Scribd company logo
1 of 37
Download to read offline
Unleash
the power of HTTP
with ASP
.NET Web API
@filip_woj
@filip_woj
www.strathweb.com
www.arcmedia.ch

@filip_woj
HTTP

@filip_woj
Trying to build a good API

@filip_woj
What is ASP
.NET Web API?




New Microsoft framework (August 2012, Version 2
October 2013) for building HTTP services & applications
Aimed at simplyfing and standardizing HTTP area on the
MS stack (see: WCF / ASMX / MVC / HttpHandlers)



HTTP as a fully fledged *application* protocol



Async from top-to-bottom



Open source!

@filip_woj
“ASP
.NET” “Web API”


The name creates lots of misconceptions



“ASP
.NET”:
it doesn't require neither ASP
.NET, nor IIS to run



“Web API”:
it's an HTTP framework, that can do much more than "just" API

@filip_woj
How can it work without ASP
.NET/IIS?


Web hosting:
ASP
.NET & IIS



Self hosting: (using WCF hardened core)
WPF
Windows service
console app, any other .NET app



OWIN (i.e. Katana)



Memory hosting: whole pipeline running in memory
@filip_woj
Demo: first API – self hosted

@filip_woj
New HTTP object model


Strongly typed HttpResponseMessage



Strongly typed HttpRequestMessage



Strongly typed Headers



Strongly typed HttpContent



No more “angle brackets coding” & magic strings



Asynchronous API



Client-server symmetry
@filip_woj
HTTP status codes
HTTP status codes


1xx – Informational



2xx – Successful



3xx – Redirection



4xx – Error on the client side



5xx – Error on the server side

@filip_woj
Demo: Created 201 / BadRequest 400

@filip_woj
HTTP headers – request


Request headers (selected)



Authorization, Cache-Control, Range




Accept, Accept-Language, Accept-Encoding

If-Match, If-Modified-Since, If-Range

Content headers (selected)


Allow, Content-Encoding, Content-Language



Content-Length, Content-Type, Expires



Last-Modified
@filip_woj
HTTP headers – response


Response headers (selected)



Cache-control, Date, Etag




Accept-Ranges, Connection

RetryAfter, Warning, Location

Content headers (selected)


Allow, Content-Encoding, Content-Language



Content-Length, Content-Type, Expires



Last-Modified
@filip_woj
RPC


/api/GetTeams



/api/GetTeam?id=1



/api/GetPlayersByTeam?id=1



/api/AddTeam



/api/UpdateTeam



/api/UpdateTeam?id=1&name=”Leafs”



/api/DeleteTeam?id=1
@filip_woj
From: presentation by @alexbeletsky
HTTP verbs


Represent core operations on a resource:

- GET: read, cachable, retreives a resource

- POST: non-cacheable, creates a resource
- PUT: updates a resource, safe to call multiple times
- DELETE: deletes a resource, safe to call multiple times


Can also use others i.e. PATCH (partial update of a
resource)
@filip_woj
RESTful


GET /api/teams



GET /api/teams/1



GET /api/teams/1/players



POST /api/teams



PUT /api/teams/1



DELETE /api/teams/1

@filip_woj
Much better

@filip_woj
Controllers


Represent your API resources



Similar as in MVC



Routing engine determines which controller to use



Web API 2 introduces attribute routing



Supports nested resources

@filip_woj
Dispatching actions


By default HTTP verb based (RESTful)



Actions matched:






by prefix (i.e. GetAll, GetById) or

by action attribute (i.e. [HttpPost])

Can be changed to action based (RPC style)

@filip_woj
Don’t be scared of REST

@filip_woj
Content negotiation


Dynamically deciding the media type



Same data can be represented in various formats:
- JSON

– XML
– CSV
– binary

– anything to what your data can be serialized/deserialized from


In Web API done with MediaTypeFormatters
@filip_woj
Content negotiation in Web API


Web API uses the following precedence:
1. MediaTypeMapping


/api/resource.json, /api/resource?format=json

2. Accept headers


Accept: application/json

3. Content type header


Content-Type: text/xml

4. MediaTypeFormatter order & check whether a formatter can
serialize/deserialize a given type
@filip_woj
Demo: Not Acceptable 406

@filip_woj
Extending content negotiation


Very easy, some examples:

- BSON (binary JSON)
- ServiceStack.Text (instead of JSON.NET)
- MessagePack
- Mobi (returning ebook!)

- RSS/Atom
- Supporting Razor views (text/html)
@filip_woj
Client-server symmetry

By: Henrik Frystyk Nielsen



Message handlers can run on server and on the client



HttpServer is a message handler itself
@filip_woj
Sample Handler
Demo: Memory hosted

@filip_woj
@filip_woj

More Related Content

What's hot

Content-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache SlingContent-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache Sling
Fabrice Hong
 

What's hot (20)

Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Unlocking the Magical Powers of WP_Query
Unlocking the Magical Powers of WP_QueryUnlocking the Magical Powers of WP_Query
Unlocking the Magical Powers of WP_Query
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPress
 
Building RESTful APIs
Building RESTful APIsBuilding RESTful APIs
Building RESTful APIs
 
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
 
RESTful web apps with Apache Sling - 2013 version
RESTful web apps with Apache Sling - 2013 versionRESTful web apps with Apache Sling - 2013 version
RESTful web apps with Apache Sling - 2013 version
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
 
Effective Web Application Development with Apache Sling
Effective Web Application Development with Apache SlingEffective Web Application Development with Apache Sling
Effective Web Application Development with Apache Sling
 
Content-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache SlingContent-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache Sling
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Using multi-tenant WordPress to simplify development
Using multi-tenant WordPress to simplify developmentUsing multi-tenant WordPress to simplify development
Using multi-tenant WordPress to simplify development
 
Get Started in Professional WordPress Design & Development
Get Started in Professional WordPress Design & DevelopmentGet Started in Professional WordPress Design & Development
Get Started in Professional WordPress Design & Development
 
Wordcamp Toronto Presentation
Wordcamp Toronto PresentationWordcamp Toronto Presentation
Wordcamp Toronto Presentation
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Spring Boot Update
Spring Boot UpdateSpring Boot Update
Spring Boot Update
 
WordPress and Client Side Web Applications WCTO
WordPress and Client Side Web Applications WCTOWordPress and Client Side Web Applications WCTO
WordPress and Client Side Web Applications WCTO
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
The Next Step in Responsive - RESS
The Next Step in Responsive - RESSThe Next Step in Responsive - RESS
The Next Step in Responsive - RESS
 
REST API for your WP7 App
REST API for your WP7 AppREST API for your WP7 App
REST API for your WP7 App
 

Similar to Unleash the power of HTTP with ASP.NET Web API

Embrace HTTP with ASP.NET Web API
Embrace HTTP with ASP.NET Web APIEmbrace HTTP with ASP.NET Web API
Embrace HTTP with ASP.NET Web API
Filip W
 
Php Asp Net Interoperability Rc Jao
Php Asp Net Interoperability Rc JaoPhp Asp Net Interoperability Rc Jao
Php Asp Net Interoperability Rc Jao
jedt
 

Similar to Unleash the power of HTTP with ASP.NET Web API (20)

Embrace HTTP with ASP.NET Web API
Embrace HTTP with ASP.NET Web APIEmbrace HTTP with ASP.NET Web API
Embrace HTTP with ASP.NET Web API
 
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
 
Design Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John HardyDesign Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John Hardy
 
RESTful API-centric Universe
RESTful API-centric UniverseRESTful API-centric Universe
RESTful API-centric Universe
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
 
eZ Publish REST API v2
eZ Publish REST API v2eZ Publish REST API v2
eZ Publish REST API v2
 
E zsc2012 rest-api-v2
E zsc2012 rest-api-v2E zsc2012 rest-api-v2
E zsc2012 rest-api-v2
 
RESTful application with Drupal 8
RESTful application with Drupal 8RESTful application with Drupal 8
RESTful application with Drupal 8
 
WP REST API - Building a simple Web Application
WP REST API - Building a simple Web ApplicationWP REST API - Building a simple Web Application
WP REST API - Building a simple Web Application
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
07 restful webservices design
07 restful webservices design07 restful webservices design
07 restful webservices design
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmers
 
LAJUG Napster REST API
LAJUG Napster REST APILAJUG Napster REST API
LAJUG Napster REST API
 
Play with force.com metadata
Play with force.com metadataPlay with force.com metadata
Play with force.com metadata
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Programmatic access to wormbase data WormBase Workshop International Worm Mee...
Programmatic access to wormbase data WormBase Workshop International Worm Mee...Programmatic access to wormbase data WormBase Workshop International Worm Mee...
Programmatic access to wormbase data WormBase Workshop International Worm Mee...
 
Php Asp Net Interoperability Rc Jao
Php Asp Net Interoperability Rc JaoPhp Asp Net Interoperability Rc Jao
Php Asp Net Interoperability Rc Jao
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
High quality ap is with api platform
High quality ap is with api platformHigh quality ap is with api platform
High quality ap is with api platform
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Unleash the power of HTTP with ASP.NET Web API