1 00:00:00,200 --> 00:00:04,290 When we make a GET request against our entry's endpoint using Postman, 2 00:00:04,290 --> 00:00:07,570 we can see that the response contains JSON formatted data. 3 00:00:09,020 --> 00:00:12,930 While there are no restrictions on the format of data that Rest APIs return in 4 00:00:12,930 --> 00:00:17,810 their responses, the majority of APIs return JSON, or 5 00:00:17,810 --> 00:00:21,480 JavaScript object notation formatted data. 6 00:00:21,480 --> 00:00:24,910 JSON, it's easy for humans to read and write. 7 00:00:24,910 --> 00:00:27,470 And it's easy for machines to parse and generate. 8 00:00:31,050 --> 00:00:34,701 This opening bracket, which is closed all the way down here, 9 00:00:37,900 --> 00:00:40,560 Indicates a list or array of values. 10 00:00:46,438 --> 00:00:51,220 A set of curly braces indicates a collection of name value pairs. 11 00:00:51,220 --> 00:00:54,290 Which is commonly referred to as an object. 12 00:00:54,290 --> 00:00:57,289 Each object property has a name in double quotes, 13 00:01:00,659 --> 00:01:05,270 Followed by a colon and then the property value. 14 00:01:05,270 --> 00:01:09,730 A property value can be a string in double quotes or as you see here for 15 00:01:09,730 --> 00:01:12,150 the ID property, a number. 16 00:01:12,150 --> 00:01:16,150 Or it could even be true or false or null. 17 00:01:17,960 --> 00:01:22,890 Most if not all modern languages provide support for working with JSON. 18 00:01:22,890 --> 00:01:26,900 And as you might expect, given that the name of the data format contains the word 19 00:01:26,900 --> 00:01:31,910 JavaScript, it's very easy to work with JSON when writing JavaScript code. 20 00:01:31,910 --> 00:01:35,808 For more information on JSON, see the teachers notes. 21 00:01:40,551 --> 00:01:44,640 We're returning the collection of entry objects from our Get method. 22 00:01:44,640 --> 00:01:48,440 So how was our collection being serialized to JSON? 23 00:01:48,440 --> 00:01:52,850 What we're seeing in action is a feature called, content negotiation. 24 00:01:52,850 --> 00:01:58,260 By returning a collection of objects or a single object from an action method, 25 00:01:58,260 --> 00:02:02,240 we're allowing Web API to inspect the incoming request and 26 00:02:02,240 --> 00:02:06,260 determine the best data format to use when serializing our data. 27 00:02:07,880 --> 00:02:11,590 In Postman, we can add an accept header to our request. 28 00:02:11,590 --> 00:02:15,464 And set its value to a media type representing our preferred data format. 29 00:02:21,715 --> 00:02:25,661 Media types are two part identifiers for file, content or 30 00:02:25,661 --> 00:02:29,320 data formats that are used on the Internet. 31 00:02:29,320 --> 00:02:34,217 And media type consists of a top-level type name and a Sub-Type name. 32 00:02:34,217 --> 00:02:39,190 Common Top-Level names include application, audio, 33 00:02:39,190 --> 00:02:43,010 font, image, text, and video. 34 00:02:43,010 --> 00:02:47,305 Though, when working with services, you'll most often use application and text. 35 00:02:47,305 --> 00:02:52,000 Sub-Type names typically consist of a Media Type name. 36 00:02:52,000 --> 00:02:56,270 Common rest API media types include json, xml, and 37 00:02:56,270 --> 00:03:00,990 x-www-form-urlencoded. 38 00:03:00,990 --> 00:03:06,613 Putting it all together, you end up with application/json, 39 00:03:06,613 --> 00:03:12,991 application/xml, and application/x-www-form-urlencoded. 40 00:03:14,100 --> 00:03:18,242 If we send an accept header value of application/json, 41 00:03:18,242 --> 00:03:22,660 we'll receive JSON-formatted data in the response body. 42 00:03:31,916 --> 00:03:36,185 If we send a value of application/XML, 43 00:03:38,800 --> 00:03:40,907 We'll receive XML formatted data. 44 00:03:46,625 --> 00:03:50,850 To serialize our data to the client's preferred data format, 45 00:03:50,850 --> 00:03:53,336 Web API uses a media type formatter. 46 00:03:53,336 --> 00:03:58,850 Media type formatters are used to not only serialize outgoing data to response 47 00:03:58,850 --> 00:04:04,478 message bodies, but also to de-serialize incoming data from request message bodies. 48 00:04:04,478 --> 00:04:09,664 Web API's built-in media type formatters provides support for 49 00:04:09,664 --> 00:04:14,400 JSON, XML, BSON, and form URL-encoded data. 50 00:04:14,400 --> 00:04:18,070 You can also create your own custom media type formatters. 51 00:04:18,070 --> 00:04:21,321 For more information on how to do that, see the teacher's notes. 52 00:04:24,476 --> 00:04:29,140 Web APIs built-in JSON media type formatter utilizes the popular 53 00:04:29,140 --> 00:04:31,530 Json.NET framework. 54 00:04:31,530 --> 00:04:36,060 In the next section, we'll see how we can configure the Json.NET serializer 55 00:04:36,060 --> 00:04:38,440 to refine the results returned to the client. 56 00:04:39,590 --> 00:04:43,100 By delegating the responsibility of serializing our data or 57 00:04:43,100 --> 00:04:45,750 allowing Web API to enable the client 58 00:04:45,750 --> 00:04:50,390 to specify the response message body data format that they prefer. 59 00:04:50,390 --> 00:04:52,750 This is the power of content negotiation. 60 00:04:52,750 --> 00:04:57,476 Now that we've taken a closer look at how our data flows from controller 61 00:04:57,476 --> 00:04:59,539 action methods to responses. 62 00:04:59,539 --> 00:05:02,855 In the next video let's look at the reverse scenario, 63 00:05:02,855 --> 00:05:06,760 how data flows from requests to our controller action methods.