Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"


0 (0 Likes / 0 Dislikes)
  • Embed Video

  • Embed normal player Copy to Clipboard
  • Embed a smaller player Copy to Clipboard
  • Advanced Embedding Options
  • Embed Video With Transcription

  • Embed with transcription beside video Copy to Clipboard
  • Embed with transcription below video Copy to Clipboard
  • Embed transcript

  • Embed transcript in:
    Copy to Clipboard
  • Invite a user to Dotsub
[Microsoft] [] [Visual Studio 2012 & One ASP.NET - Scott Hanselman, Principal Community Architect, Microsoft Corporation] Hi, this is Scott Hanselman, and I wanted to talk to you for a second about Visual Studio 2012 and ASP.NET 4.5— in this video specifically, ASP.NET Web API. [ASP.NET Web API - Scott Hanselman, Principal Program Manager, Microsoft Corporation] Web API is part of the ASP.NET technologies, and it fits in nicely with web forms, web pages, or MVC. Right now it's included when you say File, New Project with an ASP.NET MVC application. It's a great way to make REST-based services of any kind. Let's take a look at a few demos. It's a really great way to make REST services that return any kind of resource. Let's take a look. I'll say New Project, ASP.NET MVC, and one of the choices is Web API. We'll hit OK. A Web API controller derives from ApiController. ASP.NET Web API makes some interesting decisions around convention versus configuration. In this example here we've got one called values. It has a function called Get. By virtue of the name of that function, this method will be called when I issue a Get. The routing table for Web API by default puts them at api/controller name. So this controller will be at api/values. I'm going to use Google Chrome rather than Internet Explorer because it's a little more relaxed about JavaScript, especially when you're downloading a JSON payload or an XML payload. We'll hit our Web API application and hit /api/values. You notice that right there I get an XML document representing 2 strings. Those are the 2 strings that I returned right here. Let's do something a little bit more interesting. Let's make a new public class Person. Let's give Person an ID and a First name and a Last name. Now instead of a ValuesController, why don't we change Values to Person. And instead of returning a string, we will return a Person. And instead of returning strings and instead of moving strings around, let's move Persons around. So our Get will return an array of Person. I'll make a couple of people here. We'll change this to a List of Person. So now we have a PersonController that returns an IEnumerable of Person. We'll pretend that this is a little database here. Let's go and take a look at that. /api/Person. And then we've got immediately an XML representation of an array or a list of Persons. That's what happened by default. But one of the things that ASP.NET Web API does really well, and we'll look at this in Fiddler, it respects HTTP. ASP.NET Web API really likes HTTP. That means it follows all of the rules of HTTP, and one of those is, "What types do you accept?" If we take a look at this request in Fiddler, we can see in the headers that this browser is announcing that it would like HTML or XML. What if we replayed that? Let's drag that into Fiddler and replay. Instead of accepting text/html, what if we said we would like text/json? We're making a call to the exact same location, the exact same API, the exact same controller, same URL. We're requesting the same resource, except here we're saying we accept text/json. We make that call from Fiddler and our application returns JSON. So the resource that's returned matches what the client asked for. You could conceive of an extension to Web API where you might say, "I would like to request an image," or, "I would like to request a vCard to download into Outlook," and rather than a JSON representation of a person or an XML representation of a person, we would return a picture of that person or perhaps a vCard. The same thing can happen on a post. Let's look at this. The Get function was called because it was called Get. That was literally the name of the function, and it matched the verb. Here if we post the exact same resource location, we'll pull a person out of the body of the request. Let's put a breakpoint right there. We'll fire this up again, except this time from Fiddler we're going to take this request and rather than sending a GET, we're going to send a POST. And rather than sending a list of things that we accept, we'll say here's the Content-Type of this request. We're saying, "We are sending you JSON right now." I"ll modify this JSON a little bit, make a new Scott, and then post to the same location. Hit Execute and notice that we've automatically broken at our breakpoint in Visual Studio. And if I hover over value, we've actually deserialized that JSON. We've pulled it out of the HTTP request. The FromBody attribute that decorates this methods parameter handled automatically deserializing that person. I'm just scratching the surface of what ASP.NET Web API can do. It's the easiest way to make RESTful services today using ASP.NET. [Microsoft] []

Video Details

Duration: 6 minutes and 33 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 5
Posted by: neudesicasp on Oct 3, 2013


Caption and Translate

    Sign In/Register for Dotsub to translate this video.