Transcript Document

WebApi:
What is it? How can I use it?
Guy In Front of the Room: @Derik Whittaker
What is Web Api?
Restful Framework for building
HTTP based services
What does
Restful mean?
”Rest is an architectural style
that abstracts the
architectural elements within
a distributed
hypermedia system”
-- Wikipedia
Example
Restful Url
https://api.twitter.com/1.1/statuses/retweets/2.json
HTTP Based services
done right
Are Web Api & Asp.Net Mvc the
same?
Web Api != Asp.Net MVC
Web Api can be classified as a
sibling
Is Web Api a
replacement for WCF?
Maybe…. It Depends
Use Web Api if..
•
•
•
•
•
Only working with HTTP
Want RESTful endpoints
Don’t need multiple protocols
Don’t expose SOAP endpoints
Want Simple Configuration
Use WCF if..
•
•
•
•
Needs to support multiple protocols
Need to expose SOAP endpoints
Need Complex Configuration
Need RPC Style Requests
Why use Web Api?
Minimal Friction
Want multiple Hosting options
Want HTTP
based endpoints
Want Self Describing
HTTP Base API
How to install Web Api?
Install via NuGet
Web Api Features
•
•
IIS Hosted
Hosting
Self
Hosted
Options
Publicly Invokeable Methods
•
•
Actions
Get, Post, Delete, Put, etc
•
Can return data
•
Can have filters
•
Finds Controller Actions
•
Routing
3 Components
•
•
Controller/Action/Parameter
Multiple Ways to Configure
Method of intercepting calls
•
•
Action Filters
Almost like using an AOP framework
Can be applied to:
•
•
Globally/Controller level/Each Action
•
Dynamic Type Transformation
•
Model
Binding
Allows
Validation
•
Allows Under/Over Posting
•
•
•
Media Type Negotiation
Content
Negotiation
Encoding Type
Negotiation
Custom Serializers
Demo
Wrap Up
Thank you!
@derikwhittaker
http://devlicio.us/blogs/derik_whittaker
http://www.linkedin.com/in/derikwhittaker
http://bit.ly/DerikWhittaker_PS
Hope you enjoyed the session!