SlideShare uma empresa Scribd logo
1 de 43
WEB API 2.X
What’s new and …..
Ugo Lattanzi
Head of Technologies @ Gaia
Microsoft MVP, MCP
Twitter: @imperugo
Blog (en): http://tostring.it
Blog (it): http://imperugo.tostring.it
E-mail: imperugo@gmail.com
Agenda
• Who am I?
• What’s ASP.NET Web API?
• What’s a RESTful service?;
• Routing old and new;
• Global Error Handling;
• Help Page;
• CORS;
• BSON serialization;
• Ignore route;
• …. caching;
WHO AM I?
Who am I?
• Head of Technologies at Gaia (www.gaia.is.it);
• Microsoft MVP (ASP.NET / IIS);
• Speaker / Trainer;
• Book / Article author;
• “Opensourcer”;
• Github lover;
• Everything about Web Dev;
What’s ASP.NET Web API?
Web API and REST
• When you speak about Web API, probably you should
know REST, but was does it mean?
• RESTfull= REpresentational State Transfer
RESTful what????
Web API and REST
It is not a WebService (SOAP), a pattern or a
protocol, but is a style of software architecture for
distributed systems such as the World Wide Web
Web API and REST
ASP.NET Web API is a framework (FW 4.x) for processing
data and returning data, typically in json or xml (RESTful
services);
It seems like MVC but it isn't, if you need both, use both.
What is similar to MVC?
• Released with NuGet;
• Routing;
• Controllers and Actions;
• Filters;
• ModelBindings;
• Dependency Injection;
What is different from MVC?
• Dispatching (based on http verbs);
• Formatters;
• Async everywhere;
• Self hosted (no need for IIS);
• Content negotiation;
• Everything is under System.Web.Http;
RESTful
• Stateless architecture based on HTTP;
• Each url is a resources (no transaction between two
requests);
• Base on HTTP Verbs (GET, POST, PUT, DELETE);
• The status of the response is based on HTTP Status code
(401, 200, 404 and so on);
DEMO
ROUTING
Attribute Routing
Allows you to override the default routing for a single
action/controller;
/customers/1/orders
/api/v1/products
/api/v2/products
Good Article: http://bit.ly/1dwdc2D
GLOBAL ERROR
HANDLING
Global error handling (the problem)
There’s no easy way in Web API to log or handle errors
globally (prev v2.x);
I.E.:
• Exceptions thrown from controller constructors
• Exceptions thrown from message handlers
• Exceptions thrown during routing
• Exceptions thrown during response content serialization
Good Article: http://bit.ly/1eiUvBB
Global error handling (the solution)
WEB API (2.x) provides two new user-replaceable
services, IExceptionLogger and IExceptionHandler, to
log and handle unhandled exceptions. The services are
very similar, with two main differences:
Global error handling (the solution)
Global error handling (CatchBlock)
DOCUMENTATION
There is a specific endpoint to call
Help Page
• “Automatic” API Documentation;
• Based on MVC (all via nuget);
• Template on top of Bootstrap
• Support validation attributes;
• Code comments;
• Support complex types also for GET Methods (new);
• Support for Enums;
Help Page (Document your code)
Help Page (Enable the XML output)
Help Page (Specify the documentation
file)
Do you know postman?
CORS
CORS - Cross-Origin Resource Sharing -
(the problem)
By default it's not possible to make HTTP requests using
Javascript from a source domain that is different from the
called endpoint.
For example, this means that it's not possible to call the
URL http://mysite.com/api/myrestendpoint from a domain
http://yoursite.com
This limitation was introduced for security reasons: in
fact, without this protection, malicious javascript code could
get info from another site with the user noticing.
CORS (the problem)
CORS (the problem)
Ok, but sometimes we need to do this. How can we do
that?
• JSONP is easy to use and it's supported by all browsers;
the only problem is that the only HTTP VERB supported is
GET, which has a limitation on the length of the string that
can be passed as query parameter.
• Otherwise, if you need to send lot of information we can't
use this way, so the soulution could be to "proxy" the
request locally and forward the data server side or to use
CORS.
CORS (the solution)
Basically CORS communication allow you to bypass the
problem by defining some rules that makes the request
more "secure".
Of course the first thing we need is a browser that supports
CORS: fortunately all the latest browsers support it.
Anyway, we have to consider that, looking at the real
world, there are several clients that are still using Internet
Explorer 8 which, among other things, doesn't fully support
CORS (IE8 has limited support for CORS).
CORS (the solution)
http://caniuse.com/cors
•Internet Explorer 10/11
•Chrome (all versions)
•Firefox 3.5+
•Safari 4.x
CORS
CORS
CORS
CACHING
CACHING
• Did you know that HTTP supports caching?
• Do we really need to use server side caching?
• What do I need to do in my code?
Caching
How does it work?
The client will ask the server if it has an updated copy of
the resource by sending some information about the
cached resources it holds using a request header
called ETag
If there are no updates, the server return 304 with an empty
body, otherwise a 200 with the new data
Caching Source: http://bit.ly/1md3r0N
Cache Cow
It’s an open source library available on nuget (the source
code is on github) that allows you to enable caching in you
APIs;
Supports different providers to store the cache
(memcache, ravendb, azure caching, Redis and so on);
Cache cow
THANKS
Ugo Lattanzi
Head of Technologies @ Gaia
Microsoft MVP, MCP
Twitter: @imperugo
Blog (en): http://tostring.it
Blog (it): http://imperugo.tostring.it
E-mail: imperugo@gmail.com

Mais conteúdo relacionado

Mais procurados

Testing Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumTesting Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumBrian Jordan
 
TiConf NY 2014 - Alloy 2.0
TiConf NY 2014 - Alloy 2.0TiConf NY 2014 - Alloy 2.0
TiConf NY 2014 - Alloy 2.0Tony Lukasavage
 
Java Restart with WebFX
Java Restart with WebFX Java Restart with WebFX
Java Restart with WebFX Nikita Lipsky
 
Making Watir and Cucumber an efficient tool for Web UI Automation
Making Watir and Cucumber an efficient tool for Web UI AutomationMaking Watir and Cucumber an efficient tool for Web UI Automation
Making Watir and Cucumber an efficient tool for Web UI AutomationRuslan Strazhnyk
 
RapidDev - Develop Titanium apps at the speed of the web!
RapidDev - Develop Titanium apps  at the speed of the web!RapidDev - Develop Titanium apps  at the speed of the web!
RapidDev - Develop Titanium apps at the speed of the web!Matt Apperson
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Web Directions
 
Symfony vs. Message Brokers
Symfony  vs.  Message BrokersSymfony  vs.  Message Brokers
Symfony vs. Message BrokersGaetano Giunta
 
I can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystem
I can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystemI can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystem
I can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystemSidu Ponnappa
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumDev9Com
 
Bring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC PlungeBring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC PlungeColdFusionConference
 
Building iOS Apps With RubyMotion
Building iOS Apps With RubyMotionBuilding iOS Apps With RubyMotion
Building iOS Apps With RubyMotionRaymond T Hightower
 
The state of packaged web apps
The state of packaged web appsThe state of packaged web apps
The state of packaged web appsCristiano Betta
 
Same-origin Policy (SOP)
Same-origin Policy (SOP)Same-origin Policy (SOP)
Same-origin Policy (SOP)Netsparker
 
WebdriverIO: the Swiss Army Knife of testing
WebdriverIO: the Swiss Army Knife of testingWebdriverIO: the Swiss Army Knife of testing
WebdriverIO: the Swiss Army Knife of testingDaniel Chivescu
 

Mais procurados (20)

Php Development Stack
Php Development StackPhp Development Stack
Php Development Stack
 
Gatsby intro
Gatsby introGatsby intro
Gatsby intro
 
Testing Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumTesting Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS Curriculum
 
10 common cf server challenges
10 common cf server challenges10 common cf server challenges
10 common cf server challenges
 
Watir
WatirWatir
Watir
 
TiConf NY 2014 - Alloy 2.0
TiConf NY 2014 - Alloy 2.0TiConf NY 2014 - Alloy 2.0
TiConf NY 2014 - Alloy 2.0
 
Java Restart with WebFX
Java Restart with WebFX Java Restart with WebFX
Java Restart with WebFX
 
Making Watir and Cucumber an efficient tool for Web UI Automation
Making Watir and Cucumber an efficient tool for Web UI AutomationMaking Watir and Cucumber an efficient tool for Web UI Automation
Making Watir and Cucumber an efficient tool for Web UI Automation
 
RapidDev - Develop Titanium apps at the speed of the web!
RapidDev - Develop Titanium apps  at the speed of the web!RapidDev - Develop Titanium apps  at the speed of the web!
RapidDev - Develop Titanium apps at the speed of the web!
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5
 
Symfony vs. Message Brokers
Symfony  vs.  Message BrokersSymfony  vs.  Message Brokers
Symfony vs. Message Brokers
 
Testing Automaton - CFSummit 2016
Testing Automaton - CFSummit 2016Testing Automaton - CFSummit 2016
Testing Automaton - CFSummit 2016
 
I can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystem
I can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystemI can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystem
I can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystem
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
 
Bring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC PlungeBring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC Plunge
 
Don't screw it up! How to build durable API
Don't screw it up! How to build durable API Don't screw it up! How to build durable API
Don't screw it up! How to build durable API
 
Building iOS Apps With RubyMotion
Building iOS Apps With RubyMotionBuilding iOS Apps With RubyMotion
Building iOS Apps With RubyMotion
 
The state of packaged web apps
The state of packaged web appsThe state of packaged web apps
The state of packaged web apps
 
Same-origin Policy (SOP)
Same-origin Policy (SOP)Same-origin Policy (SOP)
Same-origin Policy (SOP)
 
WebdriverIO: the Swiss Army Knife of testing
WebdriverIO: the Swiss Army Knife of testingWebdriverIO: the Swiss Army Knife of testing
WebdriverIO: the Swiss Army Knife of testing
 

Destaque

Web European Conference 2015 - Welcome Session
Web European Conference 2015 - Welcome SessionWeb European Conference 2015 - Welcome Session
Web European Conference 2015 - Welcome SessionUgo Lattanzi
 
Nodejs for .NET web developers
Nodejs for .NET web developersNodejs for .NET web developers
Nodejs for .NET web developersUgo Lattanzi
 
Let's play with ASP.NET 5 (vNext) RC1
Let's play with ASP.NET 5 (vNext) RC1Let's play with ASP.NET 5 (vNext) RC1
Let's play with ASP.NET 5 (vNext) RC1Ugo Lattanzi
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

Destaque (7)

Web European Conference 2015 - Welcome Session
Web European Conference 2015 - Welcome SessionWeb European Conference 2015 - Welcome Session
Web European Conference 2015 - Welcome Session
 
Nodejs for .NET web developers
Nodejs for .NET web developersNodejs for .NET web developers
Nodejs for .NET web developers
 
Let's play with ASP.NET 5 (vNext) RC1
Let's play with ASP.NET 5 (vNext) RC1Let's play with ASP.NET 5 (vNext) RC1
Let's play with ASP.NET 5 (vNext) RC1
 
ASP.NET Web Stack
ASP.NET Web StackASP.NET Web Stack
ASP.NET Web Stack
 
Owin and Katana
Owin and KatanaOwin and Katana
Owin and Katana
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Semelhante a Codemotion Rome 2014

Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Henry S
 
An Introduction to Microservices
An Introduction to MicroservicesAn Introduction to Microservices
An Introduction to MicroservicesAd van der Veer
 
Decoupled Architecture and WordPress
Decoupled Architecture and WordPressDecoupled Architecture and WordPress
Decoupled Architecture and WordPressPantheon
 
HTML5: the new frontier of the web
HTML5: the new frontier of the webHTML5: the new frontier of the web
HTML5: the new frontier of the webIvano Malavolta
 
Workshop HTML5+PhoneGap by Ivano Malavolta
Workshop HTML5+PhoneGap by Ivano Malavolta Workshop HTML5+PhoneGap by Ivano Malavolta
Workshop HTML5+PhoneGap by Ivano Malavolta Commit University
 
HTML5 Webinar - Mind Storm Software
HTML5 Webinar - Mind Storm SoftwareHTML5 Webinar - Mind Storm Software
HTML5 Webinar - Mind Storm SoftwareRomin Irani
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by GoogleASG
 
Intro to Perfect - LA presentation
Intro to Perfect - LA presentationIntro to Perfect - LA presentation
Intro to Perfect - LA presentationTim Taplin
 
Vincent biret azure functions and flow (ottawa)
Vincent biret azure functions and flow (ottawa)Vincent biret azure functions and flow (ottawa)
Vincent biret azure functions and flow (ottawa)Vincent Biret
 
Vincent biret azure functions and flow (toronto)
Vincent biret azure functions and flow (toronto)Vincent biret azure functions and flow (toronto)
Vincent biret azure functions and flow (toronto)Vincent Biret
 
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
AD113  Speed Up Your Applications w/ Nginx and PageSpeedAD113  Speed Up Your Applications w/ Nginx and PageSpeed
AD113 Speed Up Your Applications w/ Nginx and PageSpeededm00se
 
Netbeans65 Osum Slides
Netbeans65 Osum SlidesNetbeans65 Osum Slides
Netbeans65 Osum SlidesAbhishek Gupta
 
A Beginner's Guide to Client Side Development with Javascript
A Beginner's Guide to Client Side Development with JavascriptA Beginner's Guide to Client Side Development with Javascript
A Beginner's Guide to Client Side Development with JavascriptSharePoint Saturday New Jersey
 
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet backdoor
 
Top 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersTop 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersBrian Huff
 

Semelhante a Codemotion Rome 2014 (20)

Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
An Introduction to Microservices
An Introduction to MicroservicesAn Introduction to Microservices
An Introduction to Microservices
 
Decoupled Architecture and WordPress
Decoupled Architecture and WordPressDecoupled Architecture and WordPress
Decoupled Architecture and WordPress
 
HTML5: the new frontier of the web
HTML5: the new frontier of the webHTML5: the new frontier of the web
HTML5: the new frontier of the web
 
Workshop HTML5+PhoneGap by Ivano Malavolta
Workshop HTML5+PhoneGap by Ivano Malavolta Workshop HTML5+PhoneGap by Ivano Malavolta
Workshop HTML5+PhoneGap by Ivano Malavolta
 
HTML5 Webinar - Mind Storm Software
HTML5 Webinar - Mind Storm SoftwareHTML5 Webinar - Mind Storm Software
HTML5 Webinar - Mind Storm Software
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
 
Intro to Perfect - LA presentation
Intro to Perfect - LA presentationIntro to Perfect - LA presentation
Intro to Perfect - LA presentation
 
Universal apps lightning talk
Universal apps lightning talk Universal apps lightning talk
Universal apps lightning talk
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
Vincent biret azure functions and flow (ottawa)
Vincent biret azure functions and flow (ottawa)Vincent biret azure functions and flow (ottawa)
Vincent biret azure functions and flow (ottawa)
 
Vincent biret azure functions and flow (toronto)
Vincent biret azure functions and flow (toronto)Vincent biret azure functions and flow (toronto)
Vincent biret azure functions and flow (toronto)
 
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
AD113  Speed Up Your Applications w/ Nginx and PageSpeedAD113  Speed Up Your Applications w/ Nginx and PageSpeed
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
 
Netbeans65 Osum Slides
Netbeans65 Osum SlidesNetbeans65 Osum Slides
Netbeans65 Osum Slides
 
API SECURITY
API SECURITYAPI SECURITY
API SECURITY
 
A Beginner's Guide to Client Side Development with Javascript
A Beginner's Guide to Client Side Development with JavascriptA Beginner's Guide to Client Side Development with Javascript
A Beginner's Guide to Client Side Development with Javascript
 
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
 
HTML 5
HTML 5HTML 5
HTML 5
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 
Top 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud DevelopersTop 10 HTML5 Features for Oracle Cloud Developers
Top 10 HTML5 Features for Oracle Cloud Developers
 

Último

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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 DevelopmentsTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
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 2024The Digital Insurer
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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...Martijn de Jong
 
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
 
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 WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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...
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
+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...
 

Codemotion Rome 2014

  • 1. WEB API 2.X What’s new and ….. Ugo Lattanzi Head of Technologies @ Gaia Microsoft MVP, MCP Twitter: @imperugo Blog (en): http://tostring.it Blog (it): http://imperugo.tostring.it E-mail: imperugo@gmail.com
  • 2. Agenda • Who am I? • What’s ASP.NET Web API? • What’s a RESTful service?; • Routing old and new; • Global Error Handling; • Help Page; • CORS; • BSON serialization; • Ignore route; • …. caching;
  • 4. Who am I? • Head of Technologies at Gaia (www.gaia.is.it); • Microsoft MVP (ASP.NET / IIS); • Speaker / Trainer; • Book / Article author; • “Opensourcer”; • Github lover; • Everything about Web Dev;
  • 6. Web API and REST • When you speak about Web API, probably you should know REST, but was does it mean? • RESTfull= REpresentational State Transfer
  • 8. Web API and REST It is not a WebService (SOAP), a pattern or a protocol, but is a style of software architecture for distributed systems such as the World Wide Web
  • 9. Web API and REST ASP.NET Web API is a framework (FW 4.x) for processing data and returning data, typically in json or xml (RESTful services); It seems like MVC but it isn't, if you need both, use both.
  • 10. What is similar to MVC? • Released with NuGet; • Routing; • Controllers and Actions; • Filters; • ModelBindings; • Dependency Injection;
  • 11. What is different from MVC? • Dispatching (based on http verbs); • Formatters; • Async everywhere; • Self hosted (no need for IIS); • Content negotiation; • Everything is under System.Web.Http;
  • 12. RESTful • Stateless architecture based on HTTP; • Each url is a resources (no transaction between two requests); • Base on HTTP Verbs (GET, POST, PUT, DELETE); • The status of the response is based on HTTP Status code (401, 200, 404 and so on);
  • 13. DEMO
  • 15. Attribute Routing Allows you to override the default routing for a single action/controller; /customers/1/orders /api/v1/products /api/v2/products Good Article: http://bit.ly/1dwdc2D
  • 17. Global error handling (the problem) There’s no easy way in Web API to log or handle errors globally (prev v2.x); I.E.: • Exceptions thrown from controller constructors • Exceptions thrown from message handlers • Exceptions thrown during routing • Exceptions thrown during response content serialization Good Article: http://bit.ly/1eiUvBB
  • 18. Global error handling (the solution) WEB API (2.x) provides two new user-replaceable services, IExceptionLogger and IExceptionHandler, to log and handle unhandled exceptions. The services are very similar, with two main differences:
  • 19. Global error handling (the solution)
  • 20. Global error handling (CatchBlock)
  • 22. There is a specific endpoint to call
  • 23. Help Page • “Automatic” API Documentation; • Based on MVC (all via nuget); • Template on top of Bootstrap • Support validation attributes; • Code comments; • Support complex types also for GET Methods (new); • Support for Enums;
  • 24. Help Page (Document your code)
  • 25. Help Page (Enable the XML output)
  • 26. Help Page (Specify the documentation file)
  • 27. Do you know postman?
  • 28. CORS
  • 29. CORS - Cross-Origin Resource Sharing - (the problem) By default it's not possible to make HTTP requests using Javascript from a source domain that is different from the called endpoint. For example, this means that it's not possible to call the URL http://mysite.com/api/myrestendpoint from a domain http://yoursite.com This limitation was introduced for security reasons: in fact, without this protection, malicious javascript code could get info from another site with the user noticing.
  • 31. CORS (the problem) Ok, but sometimes we need to do this. How can we do that? • JSONP is easy to use and it's supported by all browsers; the only problem is that the only HTTP VERB supported is GET, which has a limitation on the length of the string that can be passed as query parameter. • Otherwise, if you need to send lot of information we can't use this way, so the soulution could be to "proxy" the request locally and forward the data server side or to use CORS.
  • 32. CORS (the solution) Basically CORS communication allow you to bypass the problem by defining some rules that makes the request more "secure". Of course the first thing we need is a browser that supports CORS: fortunately all the latest browsers support it. Anyway, we have to consider that, looking at the real world, there are several clients that are still using Internet Explorer 8 which, among other things, doesn't fully support CORS (IE8 has limited support for CORS).
  • 33. CORS (the solution) http://caniuse.com/cors •Internet Explorer 10/11 •Chrome (all versions) •Firefox 3.5+ •Safari 4.x
  • 34. CORS
  • 35. CORS
  • 36. CORS
  • 38. CACHING • Did you know that HTTP supports caching? • Do we really need to use server side caching? • What do I need to do in my code?
  • 39. Caching How does it work? The client will ask the server if it has an updated copy of the resource by sending some information about the cached resources it holds using a request header called ETag If there are no updates, the server return 304 with an empty body, otherwise a 200 with the new data
  • 41. Cache Cow It’s an open source library available on nuget (the source code is on github) that allows you to enable caching in you APIs; Supports different providers to store the cache (memcache, ravendb, azure caching, Redis and so on);
  • 43. THANKS Ugo Lattanzi Head of Technologies @ Gaia Microsoft MVP, MCP Twitter: @imperugo Blog (en): http://tostring.it Blog (it): http://imperugo.tostring.it E-mail: imperugo@gmail.com

Notas do Editor

  1. One advantage of convention-based routing is that templates are defined in a single place, and the routing rules are applied consistently across all controllers. Unfortunately, convention-based routing makes it hard to support certain URI patterns that are common in RESTful APIs.