Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP .

13
Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP http :// debugmode.net

Transcript of Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP .

Page 1: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

Getting Started with the ASP.NET Web API

Dhananjay KumarInfragistics Consultant Microsoft MVP http://debugmode.net

Page 2: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

Some Goodies

Two active participants among you may win this cool goodies .

We will announce winner name in webinar recap blog post which will be published on Infragistics blog

Recording of the webinar with all resources will be available on webinar recap blog post

We will ask you for your mailing address and courier you the goodies in India

Page 3: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

Host : Dhananjay Kumar

Infragistics Consultant

6 times Microsoft MVP @debug_mode

Blog : http://debugmode.net

Email : [email protected]

Page 4: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

Agenda

About Web API

Write First Web API

using Scaffolding

Consuming Web API in

jQuery

Enabling CORS

Code First and

Repository Pattern in Web API

Page 5: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

What is ASP.NET Web API

Framework to create HTTP based services

Web API can be consumed by wide range of clients from browsers to mobile apps

Web API returns data based on the client request

It supports convention-based CRUD Actions since it works with HTTP verbs GET,POST,PUT and DELETE.

Page 6: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

What is ASP.NET Web API

Web API

Browsers

Mobile apps

Desktop apps

IOT

Page 7: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

ASP.NET Web API To create HTTP based service

HTTP protocol used as the application protocol

Responses have an Accept header and HTTP status code.

It works on the content negotiation from the clients. So it may return JSON or XML based on the headed of client request.

Web API can create or send in the response contents like PDF, Images etc.

It has inbuilt ODATA support. So if action has return type Iqueryable, client can apply ODATA query on that.

It can hosted in IIS or self hosted

Page 8: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

ASP.NET Web API Content Negotiation

Content negotiation is the process of selecting the best representation for a given response when there are multiple representations available

The underling Web API framework implements the content negotiation

By default it Web API returns the JSON data

While requesting for a resource client can specify the media type. Web API returns the data on the basis of the media types requested by the clients.

Page 9: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

ASP.NET Web API Demo : End to end Web API using the Scaffolding

Set up the database

Create model using the Entity framework Database first approach

Create Web API using the Scaffolding

Consume Web API in the browser to test content negotiation

Consume Web API in the jQuery based web application

Page 10: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

ASP.NET Web API Demo : Solving CORS in Web API

Enabling CORS at Controller level Enabling CORS at whole API level

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts, JavaScript, etc.) on a web page to be requested from another domain outside the domain from which the resource originated.

Page 11: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

ASP.NET Web API Demo : End to end Web API using the Code First and Repository pattern

Create the entity class

Create the DataContext classed

Create repository classes and interfaces

Create the Web API using the Repository

Consume Web API in the jQuery based web application

Page 12: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

Summary About Web API

Write First Web API using Scaffolding

Consuming Web API in jQuery

Enabling CORS

Code First and Repository Pattern in Web API

Creating Charts consuming Web API

Page 13: Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP  .

What Infragistics can offer you?• We welcome all of you to take advantage of a FREE 30 Day Trial by downloading

the product at: http://www.infragistics.com/products/ultimate/download

• Please reach out to us at [email protected] for any follow up questions you may have. We welcome the opportunity to assist you.