1 00:00:00,760 --> 00:00:05,070 We've been able to explore fairly easily just using GET requests in a browser. 2 00:00:05,070 --> 00:00:08,760 Now there comes a time in every young REST API's life when you want to simulate what 3 00:00:08,760 --> 00:00:10,860 it feels like to actually be used. 4 00:00:10,860 --> 00:00:13,860 You wanna imagine what it feels like for a client of your API. 5 00:00:13,860 --> 00:00:14,810 Well, we're at that point now. 6 00:00:15,960 --> 00:00:19,430 So there are a few command line tools that will let you post, delete and 7 00:00:19,430 --> 00:00:23,140 put data to specific resources, and I've linked to those in the teacher's notes. 8 00:00:23,140 --> 00:00:27,880 A very popular tool in the arena of API manual testing is named Postman. 9 00:00:27,880 --> 00:00:29,590 We'll get that installed here in a few. 10 00:00:29,590 --> 00:00:31,280 Since our application is HAL, or 11 00:00:31,280 --> 00:00:36,690 Hypermedia Application Language compliant, we can also use a HAL browser. 12 00:00:36,690 --> 00:00:39,400 There is a very nice packaged up version that we'll take a look at. 13 00:00:39,400 --> 00:00:40,400 It's pretty amazing. 14 00:00:40,400 --> 00:00:41,030 Let's go explore. 15 00:00:42,070 --> 00:00:45,240 Okay, so Postman is a Chrome extension and 16 00:00:45,240 --> 00:00:47,690 I've put its installation instructions in the teachers notes. 17 00:00:47,690 --> 00:00:49,600 Now this is what it looks like currently. 18 00:00:49,600 --> 00:00:51,250 Yours might look a little bit different, but 19 00:00:51,250 --> 00:00:53,900 don't worry, this tool just keeps getting better. 20 00:00:53,900 --> 00:00:56,990 If things work a little bit different, I guarantee it's for the better. 21 00:00:56,990 --> 00:01:00,820 So Postman does an amazing job of keeping track of 22 00:01:00,820 --> 00:01:03,030 what you do history wise over here. 23 00:01:03,030 --> 00:01:05,660 And it really helps to produce valid queries. 24 00:01:05,660 --> 00:01:09,010 So just to show it off, let's take a quick look at courses. 25 00:01:09,010 --> 00:01:16,157 So I'm gonna go to http://localhost:8080 and go to courses. 26 00:01:16,157 --> 00:01:19,390 And I'm going to send a GET request. 27 00:01:19,390 --> 00:01:21,630 So we're gonna press Send, awesome. 28 00:01:21,630 --> 00:01:23,210 So here's the response. 29 00:01:23,210 --> 00:01:26,434 And one of the really cool things about this is if you click, 30 00:01:26,434 --> 00:01:27,928 you can click these links. 31 00:01:27,928 --> 00:01:30,567 And what it will do is it will make a new tab up here, and 32 00:01:30,567 --> 00:01:32,754 it will do the next thing that you want to do. 33 00:01:32,754 --> 00:01:35,533 It automatically prefilled that for me, so we can click Send, so 34 00:01:35,533 --> 00:01:37,850 we can kind of navigate through the API. 35 00:01:37,850 --> 00:01:38,865 Pretty nice, right? 36 00:01:38,865 --> 00:01:44,010 So let's go ahead, and this is this course here, Groovy for Neckbeards. 37 00:01:44,010 --> 00:01:46,700 Let's go ahead and write a review for this course. 38 00:01:46,700 --> 00:01:48,850 This is course number five here. 39 00:01:48,850 --> 00:01:53,589 So the way that we add a review is we go to our reviews collection, which, 40 00:01:53,589 --> 00:01:55,705 remember, is that /reviews. 41 00:01:55,705 --> 00:02:00,920 And we want to make a new one so we're gonna to make a POST, okay? 42 00:02:00,920 --> 00:02:04,570 And we're gonna send, in the body, we're gonna send the review actually so 43 00:02:04,570 --> 00:02:07,560 we want raw, and we're gonna send application JSON, right? 44 00:02:07,560 --> 00:02:11,320 That's the way that our REST API has decided that it's gonna communicate. 45 00:02:11,320 --> 00:02:16,706 So we're gonna choose proper JSON, and we're gonna say reading is, 46 00:02:16,706 --> 00:02:20,279 let's see, Groovy for Neckbeards is a four. 47 00:02:20,279 --> 00:02:24,450 And the description we'll give a proper 48 00:02:24,450 --> 00:02:29,120 neckbeard description is Well, actually. 49 00:02:30,940 --> 00:02:36,072 Right, so in order to send what course we're talking about, 50 00:02:36,072 --> 00:02:40,414 the way that Spring Hedo us works out of the gate is you 51 00:02:40,414 --> 00:02:44,873 pass either the URL for the course resource or he URI. 52 00:02:44,873 --> 00:02:46,810 So let's go ahead and let's pass the URI. 53 00:02:46,810 --> 00:02:50,270 So we're gonna say that the course, 54 00:02:50,270 --> 00:02:56,641 that's the course property that's on there, is /courses/5. 55 00:02:56,641 --> 00:02:59,746 That's gonna use that URL to find exactly what we were talking about, right, so 56 00:02:59,746 --> 00:03:02,390 that's the link that we're passing around. 57 00:03:02,390 --> 00:03:03,700 Again, remember this is down here. 58 00:03:03,700 --> 00:03:06,500 courses/5, courses/5. 59 00:03:06,500 --> 00:03:07,750 So we're gonna add that. 60 00:03:07,750 --> 00:03:10,170 So we're doing a POST, and when I switched that to JSON application, 61 00:03:10,170 --> 00:03:10,793 look what it did. 62 00:03:10,793 --> 00:03:14,875 It set our request header to say Content-Type application/json. 63 00:03:14,875 --> 00:03:17,640 Awesome, did that for us. 64 00:03:17,640 --> 00:03:20,487 Okay, so then let's go ahead and click Send. 65 00:03:20,487 --> 00:03:25,284 And we got a bad request, which is good, to see an error like this. 66 00:03:25,284 --> 00:03:26,691 Look, I got a bad JSON. 67 00:03:26,691 --> 00:03:28,301 Bad, bad JSON. 68 00:03:28,301 --> 00:03:30,500 There we go, let's try this one more time. 69 00:03:30,500 --> 00:03:34,121 I'm gonna click send, and boom, 201 created. 70 00:03:34,121 --> 00:03:38,020 And you'll see here that it's 4, and we'll actually, and look, it's got a new ID. 71 00:03:38,020 --> 00:03:40,933 So there's a reviews/102, and you can go see that. 72 00:03:40,933 --> 00:03:44,150 And if you go to reviews/102 by clicking it, I'm gonna click send again, 73 00:03:44,150 --> 00:03:47,535 you see that it says, well, actually, and here is the course that was reviewed. 74 00:03:47,535 --> 00:03:50,939 Awesome, so if we come and do Send, and see, 75 00:03:50,939 --> 00:03:54,176 we can navigate all the way around our API. 76 00:03:54,176 --> 00:03:59,370 You know what, I saw something when I was looking at this reviews list here. 77 00:03:59,370 --> 00:04:00,400 I saw something. 78 00:04:02,310 --> 00:04:04,580 Down here it says this this profile link here. 79 00:04:04,580 --> 00:04:07,270 So it says profile/reviews. 80 00:04:07,270 --> 00:04:10,100 So I'm gonna ahead and click that, cuz why not? 81 00:04:10,100 --> 00:04:11,230 Cuz we can navigate around. 82 00:04:11,230 --> 00:04:12,230 Now let's see what this is. 83 00:04:13,870 --> 00:04:19,375 So this is ALPS, it's what is known as ALPS, application level profile semantics. 84 00:04:19,375 --> 00:04:23,168 And it's a standard format that helps you to document your application in 85 00:04:23,168 --> 00:04:24,610 a standard way. 86 00:04:24,610 --> 00:04:27,140 And we have one up here for courses as well. 87 00:04:27,140 --> 00:04:31,500 So if you go to profile/courses, so this is the course representation and 88 00:04:31,500 --> 00:04:34,400 it's got these different descriptors and it's a format. 89 00:04:34,400 --> 00:04:36,290 It's a standard format. 90 00:04:36,290 --> 00:04:40,060 And there's tools that consume this and generate documentation. 91 00:04:40,060 --> 00:04:43,100 Even live sites that let you interact with your API live. 92 00:04:43,100 --> 00:04:45,960 Now this is just one of several standards. 93 00:04:45,960 --> 00:04:50,411 So if you want to make this thing a little bit more specific to what were pushing out 94 00:04:50,411 --> 00:04:54,938 if we wanted to customize this at all, I bet you can guess what we would do, right? 95 00:04:54,938 --> 00:04:58,350 So what we would do was, we would add a properties file and 96 00:04:58,350 --> 00:05:00,209 do some configuration there. 97 00:05:00,209 --> 00:05:03,617 So these are actually in another configuration file, 98 00:05:03,617 --> 00:05:08,516 much like application properties, so if we make a new file in resources here, 99 00:05:11,121 --> 00:05:18,860 And we call it rest-messages.properties. 100 00:05:18,860 --> 00:05:23,035 And the way that this works is you do 101 00:05:23,035 --> 00:05:27,755 rest.description and then the name of the entity, which, 102 00:05:27,755 --> 00:05:29,635 in our case, we wanna change that course page, right. 103 00:05:29,635 --> 00:05:30,825 So we'll say course. 104 00:05:30,825 --> 00:05:35,709 Now at this top level, what we wanna do is we wanna say course= so 105 00:05:35,709 --> 00:05:38,252 we can explain what this is here. 106 00:05:38,252 --> 00:05:42,800 So this is a collection of online courses. 107 00:05:42,800 --> 00:05:45,840 So if somebody was looking at this, they would know what we meant by course, 108 00:05:45,840 --> 00:05:47,170 like it's not a meal. 109 00:05:47,170 --> 00:05:51,580 It's a collection of online courses, because that could still be misconstrued. 110 00:05:51,580 --> 00:05:53,570 So let's go ahead and do this. 111 00:05:53,570 --> 00:05:59,180 So we can say specifically the course.title. 112 00:05:59,180 --> 00:06:03,760 We can help explain a little bit more, document the name of the course. 113 00:06:04,790 --> 00:06:12,640 And then let's do rest.description.course.url. 114 00:06:12,640 --> 00:06:20,490 And this is link of where to find the course online. 115 00:06:20,490 --> 00:06:28,466 So now let's go ahead, let's restart our server. 116 00:06:28,466 --> 00:06:31,900 Let's go, make sure that that updated our ALPS. 117 00:06:31,900 --> 00:06:36,316 So when you click Send again, we're on profile courses. 118 00:06:36,316 --> 00:06:38,406 And boom, here it's talking about, 119 00:06:38,406 --> 00:06:41,840 now we have documentation that we're providing for our API. 120 00:06:41,840 --> 00:06:43,000 Pretty slick, right? 121 00:06:43,000 --> 00:06:46,750 And again, there's tools that read this, but not everybody reads ALPS. 122 00:06:46,750 --> 00:06:49,468 There's another standard called JSON schema, and 123 00:06:49,468 --> 00:06:51,699 it would be nice if we did that too, right? 124 00:06:51,699 --> 00:06:54,402 So we could probably write that, but before you do that, I know, 125 00:06:54,402 --> 00:06:56,260 this is getting a little ridiculous. 126 00:06:56,260 --> 00:06:57,695 It can generate that too. 127 00:06:57,695 --> 00:07:02,050 So simply by adding an accept header in here. 128 00:07:02,050 --> 00:07:07,972 If we come up to our headers here and we add Accept, and we say application, 129 00:07:07,972 --> 00:07:13,900 this is not in the dropdown, cuz it's sort of a new thing, schema+json. 130 00:07:13,900 --> 00:07:18,598 And when we refresh, it's gonna change to match this other standard and 131 00:07:18,598 --> 00:07:20,940 we didn't have to write that. 132 00:07:20,940 --> 00:07:23,940 And we didn't even have to research it, and look, it's producing and 133 00:07:23,940 --> 00:07:25,249 it's using our description. 134 00:07:25,249 --> 00:07:26,683 Super powerful. 135 00:07:26,683 --> 00:07:32,290 So cool, another standard that we didn't have to research, adhere to, and/or test. 136 00:07:32,290 --> 00:07:35,918 Again, producing these is not what our client is paying us for, right? 137 00:07:35,918 --> 00:07:38,675 Our course review client, they're not paying for this. 138 00:07:38,675 --> 00:07:42,438 But I am so glad that the Spring data REST team has taken care of this for us so 139 00:07:42,438 --> 00:07:46,230 that we don't need to write it, we can focus on the business logic. 140 00:07:46,230 --> 00:07:48,740 Now more on this and other formats in the teacher's notes. 141 00:07:48,740 --> 00:07:51,460 Speaking of other formats, why don't we take a look 142 00:07:51,460 --> 00:07:54,970 at the awesome tool Howl Browser, right after this quick break.