sagesky36
sagesky36

Reputation: 4692

How to display data after executing a Web API Get method

If ASP.Net MVC is used for returning data and displaying it in a View, and the Web API is used to transfer data, when and how would somebody display any data coming back from a Web API call?

I'm confused under what circumstances you would use one over the other. I've researched this on the web before posting and still cannot get a simple distinct answer.

I understand the Web PI is used for exposing RESTful services through HTTP, but after the data is retrieved (via a GET), what's the point of using the Web API if you can't display the data?

Any succinct explanation would be appreciated.

Upvotes: 0

Views: 1848

Answers (3)

Win
Win

Reputation: 62260

You can use Telerik kendo UI Web which is free under GPLv3. It uses knockoutjs.

Download Kendo UI Web Open Source

Kendo UI Demos

There are a lot of free ones out there, but I just happen to use that kendo UI.

Upvotes: 0

Brandon Linton
Brandon Linton

Reputation: 4411

Web API is a framework for building web services that leverage all aspects of HTTP - ASP.NET MVC is a framework for building websites.

You could use the two together; for example, you could use ASP.NET MVC to generate HTML "templates" server side and then use JavaScript on the client side to invoke your Web API resources to get and modify the data and "plug it in" to your HTML templates. Check out @Lars' answer for more info on that particular scenario and the JavaScript frameworks that make that easier. This technique is mostly used for creating more fluid user experiences over traditional websites.

A big reason to choose Web API instead of putting everything in an ASP.NET MVC website is if you ever expanded beyond a single website to multiple types of clients (e.g., smartphones, Mac / Windows applications, etc.). Since ASP.NET MVC is really geared for websites / generating HTML, whereas native clients tend to prefer simple web requests and rendering the UI client-side, a simpler approach would be to do all of your data manipulation behind a Web API and have all of your UIs consume it.

There's a ton more to say about Web API and when you'd choose it over (or in concert with) ASP.NET MVC. I actually think the more interesting tradeoffs come when you compare it to SOAP-based service stacks like WCF.

Upvotes: 0

Lars
Lars

Reputation: 589

You can use client side javascript framework such as

to retrieve and display your returned data.

Take a look at this tutorial for Knockout: http://www.asp.net/web-api/overview/creating-web-apis/using-web-api-with-entity-framework/using-web-api-with-entity-framework,-part-1

Or this one for Angular: http://code.msdn.microsoft.com/CRUD-Grid-Using-AngularJS-84afaf13

Upvotes: 1

Related Questions