SlideShare a Scribd company logo
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
Browser Request
Index.html
MVC4
Traditional Request / Response for ALL rendered content and assets
Initial Request
Application.htm
MVC4
RequireJS Loader
Page1 Partial.htm
IndexViewModel.js
Application.js (bootstrap)
ViewModel (#index)
ViewModel (#login)
Model (LoginModel)
JSON Requests
HTML5 localstorage
Handling disconnection
Source: www.programmableweb.com – current APIs: 4,535
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
POST SimpleService.asmx/EchoString HTTP/1.1
Host: localhost:1489
User-Agent: Mozilla/5.0
Accept: text/html
Content-Type: application/json;
Content-Length: 27
...
XML, JSON, SOAP, AtomPub ...
Headers
Data
Verb URL
POST SimpleService.asmx/EchoString HTTP/1.1
Host: localhost:1489
User-Agent: Mozilla/5.0
Accept: text/html,application/xhtml+xml
Content-Type: application/json;
Content-Length: 27
...
{
"Age":37,
"FirstName":"Eyal",
"ID":"123",
"LastName":"Vardi“
}
Headers
Data
Verb URL
<Envelope>
<Header>
<!–- Headers -->
<!-- Protocol's & Polices -->
</Header>
<Body>
<!– XML Data -->
</Body>
</Envelope>
SOAP REST OData JSON POX ??
Dependency Injection
Filters
Content Negotiation
Testing
Embrace HTTP
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
“An architectural style for
building distributed
hypermedia systems.”
WSDL description of a web services
types defined in <xsd:schema>
simple messages
parts of messages
interface specification
operations of an interface
input message
output message
binding of interface to protocols & encoding
description of the binding for each operation
service description
URI and binding to port
<definitions>
<types></types>
<message>
<part></part>
</message>
<portType>
<operation>
<input>
<output>
</operation>
</portType>
<binding>
<operation>
</binding>
<service>
<port>
</service>
</definitions>
ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
<?xml version="1.0" encoding="utf-8"?>
<Tasks>
<TaskInfo Id="1234" Status="Active" >
<link rel="self" href="/api/tasks/1234" method="GET" />
<link rel="users" href="/api/tasks/1234/users" method="GET" />
<link rel="history" href="/api/tasks/1234/history" method="GET" />
<link rel="complete" href="/api/tasks/1234" method="DELETE" />
<link rel="update" href="/api/tasks/1234" method="PUT" />
</TaskInfo>
<TaskInfo Id="0987" Status="Completed" >
<link rel="self" href="/api/tasks/0987" method="GET" />
<link rel="users" href="/api/tasks/0987/users" method="GET" />
<link rel="history" href="/api/tasks/0987/history" method="GET" />
<link rel="reopen" href="/api/tasks/0987" method="PUT" />
</TaskInfo>
</Tasks>
/api/tasks
ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
ASP.NET and Web Tools 2012.2 Update
Adding a simple Test
Client to ASP.NET
Web API Help Page
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
Serialization Validation
DeserializationResponse
Controller /
Action
Request
HTTP/1.1 200 OK
Content-Length: 95267
Content-Type: text/html | application/json
Accept: text/html, application/xhtml+xml, application/xml
GlobalConfiguration.Configuration.Formatters
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.UseDataContractJsonSerializer = true;
 "opt-out" approach
 "opt-in" approach
public class Product
{
public string Name { get; set; }
public decimal Price { get; set; }
[JsonIgnore]
public int ProductCode { get; set; }
}
[DataContract] public class Product
{
[DataMember] public string Name { get; set; }
[DataMember] public decimal Price { get; set; }
// omitted by default
public int ProductCode { get; set; }
}
public object Get()
{
return new {
Name = "Alice",
Age = 23,
Pets = new List<string> { "Fido", "Polly", "Spot" } };
}
public void Post(JObject person)
{
string name = person["Name"].ToString();
int age = person["Age"].ToObject<int>();
}
var xml = GlobalConfiguration.Configuration.Formatters.XmlFormatter;
xml.UseXmlSerializer = true;
The XmlSerializer class supports a narrower set of types
than DataContractSerializer, but gives more control over the resulting
XML. Consider using XmlSerializer if you need to match an existing XML
schema.
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
“the process of selecting the best
representation for a given response when
there are multiple representations
available.”
public HttpResponseMessage GetProduct(int id)
{
var product = new Product() { Id = id, Name = "Gizmo", Price = 1.99M };
IContentNegotiator negotiator = this.Configuration
.Services.GetContentNegotiator();
ContentNegotiationResult result = negotiator.Negotiate( typeof(Product),
this.Request, this.Configuration.Formatters);
if (result == null) {
var response = new HttpResponseMessage(HttpStatusCode.NotAcceptable);
throw new HttpResponseException(response));
}
return new HttpResponseMessage()
{
Content = new ObjectContent<Product>(
product, // What we are serializing
result.Formatter, // The media formatter
result.MediaType.MediaType // The MIME type
)
};
}
The Full Power of ASP.NET Web API
public class ProductMD
{
[StringLength(50), Required]
public string Name { get; set; }
[Range(0, 9999)]
public int Weight { get; set; }
}
 [Required]
 [Exclude]
 [DataType]
 [Range]
[MetadataTypeAttribute( typeof( Employee.EmployeeMetadata ) )]
public partial class Employee
internal sealed class EmployeeMetadata
[StringLength(60)]
[RoundtripOriginal]
public string AddressLine { get; set; }
}
}
 [StringLength(60)]
 [RegularExpression]
 [AllowHtml]
 [Compare]
public class ProductsController : ApiController
{
public HttpResponseMessage Post(Product product)
{
if ( ModelState.IsValid ) {
// Do something with the product (not shown).
return new HttpResponseMessage(HttpStatusCode.OK);
}
else {
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}
}
}
public class ModelValidationFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (actionContext.ModelState.IsValid == false)
{
// Return the validation errors in the response body.
var errors = new Dictionary<string, IEnumerable<string>>();
foreach ( var keyValue in actionContext.ModelState )
{
errors[keyValue.Key] =
keyValue.Value.Errors.Select(e => e.ErrorMessage);
}
actionContext.Response =
actionContext
.Request
.CreateResponse(HttpStatusCode.BadRequest, errors);
}
}
}
public class ModelValidationFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (actionContext.ModelState.IsValid == false)
{
// Return the validation errors in the response body.
var errors = new Dictionary<string, IEnumerable<string>>();
foreach ( var keyValue in actionContext.ModelState )
{
errors[keyValue.Key] =
keyValue.Value.Errors.Select(e => e.ErrorMessage);
}
actionContext.Response =
actionContext
.Request
.CreateResponse(HttpStatusCode.BadRequest, errors);
}
}
}
protected void Application_Start() {
// ...
GlobalConfiguration
.Configuration
.Filters.Add(new ModelValidationFilterAttribute());
}
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute(
"API Default", "api/{controller}/{id}",
new { id = RouteParameter.Optional });
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.ReadLine();
}
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
http://www.asp.net/web-api/
Why I’m giving REST a rest
Building Hypermedia Web APIs with ASP.NET Web API
The Full Power of ASP.NET Web API
eyalvardi.wordpress.com

More Related Content

PPTX
ASP.NET Web API
PPTX
ASP.NET WEB API Training
PPTX
ASP.NET WEB API
PPTX
ASP.NET Web API and HTTP Fundamentals
PPT
Excellent rest using asp.net web api
PPTX
ASP.NET Mvc 4 web api
PPTX
Enjoying the Move from WCF to the Web API
PPTX
Web API or WCF - An Architectural Comparison
ASP.NET Web API
ASP.NET WEB API Training
ASP.NET WEB API
ASP.NET Web API and HTTP Fundamentals
Excellent rest using asp.net web api
ASP.NET Mvc 4 web api
Enjoying the Move from WCF to the Web API
Web API or WCF - An Architectural Comparison

What's hot (20)

PPTX
Web development with ASP.NET Web API
PPTX
Overview of Rest Service and ASP.NET WEB API
PPTX
Web services - A Practical Approach
KEY
Web API Basics
PPT
Using Java to implement SOAP Web Services: JAX-WS
PPTX
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
PPTX
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - W...
PPT
Introduction to the Web API
PDF
Spring Web Services: SOAP vs. REST
PPTX
Overview of RESTful web services
PDF
Consuming RESTful services in PHP
PDF
OAuth: Trust Issues
PPTX
Building RESTfull Data Services with WebAPI
PDF
Server-Side Programming Primer
PPTX
Servletarchitecture,lifecycle,get,post
ODP
RESTful Web Services with JAX-RS
PDF
Doing REST Right
PDF
SOAP-based Web Services
PDF
Building Restful Applications Using Php
PPTX
What is an API?
Web development with ASP.NET Web API
Overview of Rest Service and ASP.NET WEB API
Web services - A Practical Approach
Web API Basics
Using Java to implement SOAP Web Services: JAX-WS
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - W...
Introduction to the Web API
Spring Web Services: SOAP vs. REST
Overview of RESTful web services
Consuming RESTful services in PHP
OAuth: Trust Issues
Building RESTfull Data Services with WebAPI
Server-Side Programming Primer
Servletarchitecture,lifecycle,get,post
RESTful Web Services with JAX-RS
Doing REST Right
SOAP-based Web Services
Building Restful Applications Using Php
What is an API?
Ad

Viewers also liked (20)

PDF
C# ASP.NET WEB API APPLICATION DEVELOPMENT
PDF
RESTful Web Services
PDF
Build Features, Not Apps
PDF
Presentation Wildix Autumn Convention 2013
PPT
UC for Cloud Apps
PPTX
WCF (Windows Communication Foundation)
PPTX
UC SDN
PPTX
REST != WebAPI
PPTX
Big Data Analytics with Spark
PPTX
UC Browser
PPTX
WCF Fundamentals
PDF
Microservices Application Simplicity Infrastructure Complexity
PPT
Asp.net Présentation de L'application "Organizer"
PPT
Web 2.0 Mashups
PPT
Server Controls of ASP.Net
PPTX
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
DOC
WCF tutorial
PDF
MicroServices, yet another architectural style?
PPT
Three layer API Design Architecture
PDF
OAuth based reference architecture for API Management
C# ASP.NET WEB API APPLICATION DEVELOPMENT
RESTful Web Services
Build Features, Not Apps
Presentation Wildix Autumn Convention 2013
UC for Cloud Apps
WCF (Windows Communication Foundation)
UC SDN
REST != WebAPI
Big Data Analytics with Spark
UC Browser
WCF Fundamentals
Microservices Application Simplicity Infrastructure Complexity
Asp.net Présentation de L'application "Organizer"
Web 2.0 Mashups
Server Controls of ASP.Net
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
WCF tutorial
MicroServices, yet another architectural style?
Three layer API Design Architecture
OAuth based reference architecture for API Management
Ad

Similar to The Full Power of ASP.NET Web API (20)

PPTX
How to get full power from WebApi
PPTX
Asp.net web api
PPTX
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
PPTX
Mastering-ASPNET-Web-API-and-RESTful-Patterns.pptx
PPTX
Rest WebAPI with OData
PPTX
2011 - DNC: REST Wars
PPTX
Wcf rest api introduction
PDF
PPTX
Will be an introduction to
ODP
Embrace HTTP with ASP.NET Web API
PDF
May 2010 - RestEasy
PPTX
Nancy + rest mow2012
PDF
Writing RESTful Web Services
PPTX
Building Software Backend (Web API)
PDF
Ws rest
PPT
Building+restful+webservice
PDF
Complete guidance book of Asp.Net Web API
PPTX
Web api
PDF
Building RESTful Services with WCF 4.0
PDF
MS TechDays 2011 - WCF Web APis There's a URI for That
How to get full power from WebApi
Asp.net web api
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
Mastering-ASPNET-Web-API-and-RESTful-Patterns.pptx
Rest WebAPI with OData
2011 - DNC: REST Wars
Wcf rest api introduction
Will be an introduction to
Embrace HTTP with ASP.NET Web API
May 2010 - RestEasy
Nancy + rest mow2012
Writing RESTful Web Services
Building Software Backend (Web API)
Ws rest
Building+restful+webservice
Complete guidance book of Asp.Net Web API
Web api
Building RESTful Services with WCF 4.0
MS TechDays 2011 - WCF Web APis There's a URI for That

More from Eyal Vardi (20)

PPTX
Why magic
PPTX
Smart Contract
PDF
Rachel's grandmother's recipes
PPTX
Performance Optimization In Angular 2
PPTX
Angular 2 Architecture (Bucharest 26/10/2016)
PPTX
Angular 2 NgModule
PPTX
Upgrading from Angular 1.x to Angular 2.x
PPTX
Angular 2 - Ahead of-time Compilation
PPTX
Routing And Navigation
PPTX
Angular 2 Architecture
PPTX
Angular 1.x vs. Angular 2.x
PPTX
Angular 2.0 Views
PPTX
Component lifecycle hooks in Angular 2.0
PPTX
Template syntax in Angular 2.0
PPTX
Http Communication in Angular 2.0
PPTX
Angular 2.0 Dependency injection
PPTX
Angular 2.0 Routing and Navigation
PPTX
Async & Parallel in JavaScript
PPTX
Angular 2.0 Pipes
PPTX
Angular 2.0 forms
Why magic
Smart Contract
Rachel's grandmother's recipes
Performance Optimization In Angular 2
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 NgModule
Upgrading from Angular 1.x to Angular 2.x
Angular 2 - Ahead of-time Compilation
Routing And Navigation
Angular 2 Architecture
Angular 1.x vs. Angular 2.x
Angular 2.0 Views
Component lifecycle hooks in Angular 2.0
Template syntax in Angular 2.0
Http Communication in Angular 2.0
Angular 2.0 Dependency injection
Angular 2.0 Routing and Navigation
Async & Parallel in JavaScript
Angular 2.0 Pipes
Angular 2.0 forms

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Cloud computing and distributed systems.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Review of recent advances in non-invasive hemoglobin estimation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Cloud computing and distributed systems.
Advanced methodologies resolving dimensionality complications for autism neur...
Unlocking AI with Model Context Protocol (MCP)
“AI and Expert System Decision Support & Business Intelligence Systems”
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
NewMind AI Monthly Chronicles - July 2025
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
Understanding_Digital_Forensics_Presentation.pptx
cuic standard and advanced reporting.pdf
Network Security Unit 5.pdf for BCA BBA.

The Full Power of ASP.NET Web API

  • 4. Browser Request Index.html MVC4 Traditional Request / Response for ALL rendered content and assets
  • 5. Initial Request Application.htm MVC4 RequireJS Loader Page1 Partial.htm IndexViewModel.js Application.js (bootstrap) ViewModel (#index) ViewModel (#login) Model (LoginModel) JSON Requests HTML5 localstorage Handling disconnection
  • 9. POST SimpleService.asmx/EchoString HTTP/1.1 Host: localhost:1489 User-Agent: Mozilla/5.0 Accept: text/html Content-Type: application/json; Content-Length: 27 ... XML, JSON, SOAP, AtomPub ... Headers Data Verb URL
  • 10. POST SimpleService.asmx/EchoString HTTP/1.1 Host: localhost:1489 User-Agent: Mozilla/5.0 Accept: text/html,application/xhtml+xml Content-Type: application/json; Content-Length: 27 ... { "Age":37, "FirstName":"Eyal", "ID":"123", "LastName":"Vardi“ } Headers Data Verb URL <Envelope> <Header> <!–- Headers --> <!-- Protocol's & Polices --> </Header> <Body> <!– XML Data --> </Body> </Envelope>
  • 11. SOAP REST OData JSON POX ??
  • 17. “An architectural style for building distributed hypermedia systems.”
  • 18. WSDL description of a web services types defined in <xsd:schema> simple messages parts of messages interface specification operations of an interface input message output message binding of interface to protocols & encoding description of the binding for each operation service description URI and binding to port <definitions> <types></types> <message> <part></part> </message> <portType> <operation> <input> <output> </operation> </portType> <binding> <operation> </binding> <service> <port> </service> </definitions>
  • 19. ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
  • 20. ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
  • 21. ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
  • 22. <?xml version="1.0" encoding="utf-8"?> <Tasks> <TaskInfo Id="1234" Status="Active" > <link rel="self" href="/api/tasks/1234" method="GET" /> <link rel="users" href="/api/tasks/1234/users" method="GET" /> <link rel="history" href="/api/tasks/1234/history" method="GET" /> <link rel="complete" href="/api/tasks/1234" method="DELETE" /> <link rel="update" href="/api/tasks/1234" method="PUT" /> </TaskInfo> <TaskInfo Id="0987" Status="Completed" > <link rel="self" href="/api/tasks/0987" method="GET" /> <link rel="users" href="/api/tasks/0987/users" method="GET" /> <link rel="history" href="/api/tasks/0987/history" method="GET" /> <link rel="reopen" href="/api/tasks/0987" method="PUT" /> </TaskInfo> </Tasks> /api/tasks
  • 23. ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
  • 30. ASP.NET and Web Tools 2012.2 Update Adding a simple Test Client to ASP.NET Web API Help Page
  • 33. Serialization Validation DeserializationResponse Controller / Action Request HTTP/1.1 200 OK Content-Length: 95267 Content-Type: text/html | application/json Accept: text/html, application/xhtml+xml, application/xml
  • 35. var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter; json.UseDataContractJsonSerializer = true;
  • 36.  "opt-out" approach  "opt-in" approach public class Product { public string Name { get; set; } public decimal Price { get; set; } [JsonIgnore] public int ProductCode { get; set; } } [DataContract] public class Product { [DataMember] public string Name { get; set; } [DataMember] public decimal Price { get; set; } // omitted by default public int ProductCode { get; set; } }
  • 37. public object Get() { return new { Name = "Alice", Age = 23, Pets = new List<string> { "Fido", "Polly", "Spot" } }; } public void Post(JObject person) { string name = person["Name"].ToString(); int age = person["Age"].ToObject<int>(); }
  • 38. var xml = GlobalConfiguration.Configuration.Formatters.XmlFormatter; xml.UseXmlSerializer = true; The XmlSerializer class supports a narrower set of types than DataContractSerializer, but gives more control over the resulting XML. Consider using XmlSerializer if you need to match an existing XML schema.
  • 41. “the process of selecting the best representation for a given response when there are multiple representations available.”
  • 42. public HttpResponseMessage GetProduct(int id) { var product = new Product() { Id = id, Name = "Gizmo", Price = 1.99M }; IContentNegotiator negotiator = this.Configuration .Services.GetContentNegotiator(); ContentNegotiationResult result = negotiator.Negotiate( typeof(Product), this.Request, this.Configuration.Formatters); if (result == null) { var response = new HttpResponseMessage(HttpStatusCode.NotAcceptable); throw new HttpResponseException(response)); } return new HttpResponseMessage() { Content = new ObjectContent<Product>( product, // What we are serializing result.Formatter, // The media formatter result.MediaType.MediaType // The MIME type ) }; }
  • 44. public class ProductMD { [StringLength(50), Required] public string Name { get; set; } [Range(0, 9999)] public int Weight { get; set; } }
  • 45.  [Required]  [Exclude]  [DataType]  [Range] [MetadataTypeAttribute( typeof( Employee.EmployeeMetadata ) )] public partial class Employee internal sealed class EmployeeMetadata [StringLength(60)] [RoundtripOriginal] public string AddressLine { get; set; } } }  [StringLength(60)]  [RegularExpression]  [AllowHtml]  [Compare]
  • 46. public class ProductsController : ApiController { public HttpResponseMessage Post(Product product) { if ( ModelState.IsValid ) { // Do something with the product (not shown). return new HttpResponseMessage(HttpStatusCode.OK); } else { return new HttpResponseMessage(HttpStatusCode.BadRequest); } } }
  • 47. public class ModelValidationFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(HttpActionContext actionContext) { if (actionContext.ModelState.IsValid == false) { // Return the validation errors in the response body. var errors = new Dictionary<string, IEnumerable<string>>(); foreach ( var keyValue in actionContext.ModelState ) { errors[keyValue.Key] = keyValue.Value.Errors.Select(e => e.ErrorMessage); } actionContext.Response = actionContext .Request .CreateResponse(HttpStatusCode.BadRequest, errors); } } }
  • 48. public class ModelValidationFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(HttpActionContext actionContext) { if (actionContext.ModelState.IsValid == false) { // Return the validation errors in the response body. var errors = new Dictionary<string, IEnumerable<string>>(); foreach ( var keyValue in actionContext.ModelState ) { errors[keyValue.Key] = keyValue.Value.Errors.Select(e => e.ErrorMessage); } actionContext.Response = actionContext .Request .CreateResponse(HttpStatusCode.BadRequest, errors); } } } protected void Application_Start() { // ... GlobalConfiguration .Configuration .Filters.Add(new ModelValidationFilterAttribute()); }
  • 52. var config = new HttpSelfHostConfiguration("http://localhost:8080"); config.Routes.MapHttpRoute( "API Default", "api/{controller}/{id}", new { id = RouteParameter.Optional }); using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.ReadLine(); }
  • 56. http://www.asp.net/web-api/ Why I’m giving REST a rest Building Hypermedia Web APIs with ASP.NET Web API

Editor's Notes

  • #3: OSScreen ResolutionDeploymentSecurityBrowsersLoad Balance
  • #14: Use HTTP as an Application Protocol – not a Transport Protocol
  • #46: [ExternalReference] [Association(&quot;Sales_Customer&quot;, &quot;CustomerID&quot;, &quot;CustomerID&quot;)]