KEMBAR78
Web api | PPTX
ASP.NET Web API
Contents
• What is an API?
• Why ASP.NET MVC Web API?
• HyperText Transfer Protocol
• REST
• JSON
• Introduction to Web API
Web API
Traditional apps
Browser Request
Index.html
MVC4
Traditional Request / Response for ALL rendered content and assets
Web Application (SPA)
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
Web API Growth
WCF vs. 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 ...
HTTP Communication
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
...
JSON vs. SOAP
{
"Age":37,
"FirstName":"Eyal",
"ID":"123",
"LastName":"Vardi“
}
Headers
Data
Verb URL
<Envelope>
<Header>
<!–- Headers -->
<!-- Protocol's & Polices -->
</Header>
<Body>
<!– XML Data -->
</Body>
</Envelope>
Protocols & Formats
SOAP REST OData JSON POX ??
ASP.NET Web API vs. ASP.NET MVC
Dependency Injection
Filters
Content Negotiation
Testing
Embrace HTTP
REST is..
“An architectural style for building
distributed hypermedia systems.”
WSDL vs. REST
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>
From RPC to REST
ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
URIs and Resources (Routing)
ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
HTTP Verbs
ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
“Hypermedia as the engine of
application state” (HATEOAS)
<?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
“Hypermedia as the engine of
application state” (HATEOAS)
ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
The Advantages of REST over SOAP
 Simpler API for CRUD
 Standardize Development methodology
 Wide industry adoption, Ease of use
 Smaller payloads than SOAP
 Testability

Web api

  • 1.
  • 2.
    Contents • What isan API? • Why ASP.NET MVC Web API? • HyperText Transfer Protocol • REST • JSON • Introduction to Web API
  • 7.
  • 11.
    Traditional apps Browser Request Index.html MVC4 TraditionalRequest / Response for ALL rendered content and assets
  • 12.
    Web Application (SPA) InitialRequest 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
  • 13.
  • 17.
  • 18.
    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 ... HTTP Communication Headers Data Verb URL
  • 19.
    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 ... JSON vs. SOAP { "Age":37, "FirstName":"Eyal", "ID":"123", "LastName":"Vardi“ } Headers Data Verb URL <Envelope> <Header> <!–- Headers --> <!-- Protocol's & Polices --> </Header> <Body> <!– XML Data --> </Body> </Envelope>
  • 20.
    Protocols & Formats SOAPREST OData JSON POX ??
  • 21.
    ASP.NET Web APIvs. ASP.NET MVC Dependency Injection Filters Content Negotiation Testing
  • 22.
  • 23.
    REST is.. “An architecturalstyle for building distributed hypermedia systems.”
  • 24.
    WSDL vs. REST WSDLdescription 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>
  • 25.
    From RPC toREST ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
  • 26.
    URIs and Resources(Routing) ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
  • 27.
    HTTP Verbs ASP.NET MVC4 and the Web API: Building a REST Service from Start to Finish book
  • 28.
    “Hypermedia as theengine of application state” (HATEOAS) <?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
  • 29.
    “Hypermedia as theengine of application state” (HATEOAS) ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish book
  • 30.
    The Advantages ofREST over SOAP  Simpler API for CRUD  Standardize Development methodology  Wide industry adoption, Ease of use  Smaller payloads than SOAP  Testability

Editor's Notes

  • #23 Use HTTP as an Application Protocol – not a Transport Protocol