Building rest services using aspnetwebapi

23
Building Rest Services Using ASP.NET Web API Brij Bhushan Mishra http://codewala.net @code_wala https://www.facebook.com/codewala

Transcript of Building rest services using aspnetwebapi

Page 1: Building rest services using aspnetwebapi

Building Rest Services Using ASP.NET Web API

Brij Bhushan Mishra

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 2: Building rest services using aspnetwebapi

About Me• Brij Bhushan Mishra

• 5 times Microsoft MVP - ASP.NET/IIS

• Architect/Consultant/ SME

• Avid Blogger/ Author/ Reviewer

• Speaker at top Conferences including GIDS,

TechEd, C# Corner Conference and many more

• Work closely with various organizations as SME, Content developer, Speaker,

Community Tech Reviewer

• http://codewala.net

• @code_wala

• https://www.facebook.com/codewala

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 3: Building rest services using aspnetwebapi

What is REST ?

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 4: Building rest services using aspnetwebapi

Everybody needs REST?

Representational State TransferRepresentational State Transfer

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 5: Building rest services using aspnetwebapi

Why are we talking about Rest?

• To Understand it, let’s talk about WCF and its working

SOAPSOAPSOAP

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 6: Building rest services using aspnetwebapi

What is Rest?• Rest is an Architectural Style

Kalinga Architecture

Mu

ghal A

rchitectu

re

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 7: Building rest services using aspnetwebapi

Rest Constraints

• Client Server

• Stateless server

• Cacheable

• Uniform Interface

• Layered System

• Code on Demand

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 8: Building rest services using aspnetwebapi

Client Server

Request

Response

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 9: Building rest services using aspnetwebapi

Stateless Sever

Request

Response

Request

Response

No State Preserved

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 10: Building rest services using aspnetwebapi

Cacheable

Request

Response

http://codewala.net @code_wala https://www.facebook.com/codewala

Request

Response

Cache

Page 11: Building rest services using aspnetwebapi

Uniform Interface

• Identification of a resource • Each resource should be identified by an Id (api/books/{id})

• Manipulation of resources through representations• Same representations should be sent back as are received via API

• Uses the standard HTTP verbs for the operation

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 12: Building rest services using aspnetwebapi

Layered System

Load BalancerProxy Server

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 13: Building rest services using aspnetwebapi

Why REST?

• Uses HTTP. Less Overhead and lightweight

• Content negotiation

• JSON vs XML

• Any Data from Any Where

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 14: Building rest services using aspnetwebapi

What is ASP.NET Web API?

ASP.NET Web API is framework that enables to write REST based services.

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 15: Building rest services using aspnetwebapi

HTTP Verbs

• GET (Reading the resource)

• POST (Create a resource)

• PUT (Update a resource)

• DELETE (Delete a resource)

• PATCH (Update a resource)

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 16: Building rest services using aspnetwebapi

Key Characteristics – Defining a Resource

• Collection or single../api/bookstore/books or /api/bookstore/books/{id}

• Noun (not a verb)

• Navigation (for associated items)

• In Web API, Noun is typically a controller

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 17: Building rest services using aspnetwebapi

Earlier versions of ASP.NET

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 18: Building rest services using aspnetwebapi

ASP.NET Core 1.0

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 19: Building rest services using aspnetwebapi

Postman – Tool for Testing Web API

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 20: Building rest services using aspnetwebapi

Lets Build our First ASP.NET Web API application

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 21: Building rest services using aspnetwebapi

Content Negotiation

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 22: Building rest services using aspnetwebapi

What we covered today

• What is not REST

• REST Constraints

• What is ASP.NET Web API

• HTTP Verbs

• ASP.NET Core ( MVC = MVC + Web API)

• POSTMAN

• Demo.. Demo..

http://codewala.net @code_wala https://www.facebook.com/codewala

Page 23: Building rest services using aspnetwebapi

Thank You

http://codewala.net @code_wala https://www.facebook.com/codewala

http://codewala.net@code_walahttps://www.facebook.com/[email protected]

http://bit.ly/1OTSgZ8