How to Build a REST API Using ASP.NET Web API Fernando Cardenas 10/8/20131
Goals Understand REST What Why Get comfortable with ASP.NET Web API 10/8/20132
Agenda Quick Demo REST and Why You Should Care Building an API with ASP.NET Web API 10/8/20133
Demo 10/8/20134
What is REST Stands For: REpresentational State Transfer Architectural Style based on HTTP 10/8/20135
What is HTTP? Well defined protocol (web browsers, web servers, etc.) Request and Response Stateless Request Contents URL HTTP Verb Header Message Body 10/8/20136
What is REST Architectural Style based on HTTP Resources (Things) Verbs (Actions) GET, POST, PUT, DELETE, etc. Response gives a representation of the resource (XML, JSON, image, etc.) More Info: 10/8/20137
Resources GET GET 10/8/20138
HTTP Verbs GET Gets 0 or more of a resource (thing) POST Creates a resource (hopefully) PUT Updates a resource (hopefully) DELETE Deletes a resource (hopefully) 10/8/20139
REST in Action Actions: GET POST PUT DELETE Resources: /8/201310
REST Responses Responses come back as an HTTP Status Code + message (maybe) HTTP Status Codes 1XX – Request Received and Im processing it 2XX – Request Received and processed it successfully! 3XX – Client must do something else to complete the request 4XX – Client made an error 5XX – Server error 10/8/201311
Popular Status Codes 200 – Success 201 – Created 301 – Moved Permanently (AKA redirect) 404 – Not Found 401 – Unauthorized 500 – Internal Server Error (AKA oh crap!) 10/8/201312
On to the codez… 10/8/201313
Why REST? Everyone/everything speaks HTTP Web applications are moving to JavaScript + AJAX Lightweight compared to SOAP Caching of resources (server decides) 10/8/201314
REST is NOT a standard 10/8/201315
Thank You! 10/8/201316