Exploring Your API With New Tools - Postman7:55 with Craig Dennis
Postman is a chrome extension that allows you to manipulate headers and keep track of history. It's a great tool for exploring APIs.
We've been able to explore fairly easily just using GET requests in a browser. 0:00 Now there comes a time in every young REST API's life when you want to simulate what 0:05 it feels like to actually be used. 0:08 You wanna imagine what it feels like for a client of your API. 0:10 Well, we're at that point now. 0:13 So there are a few command line tools that will let you post, delete and 0:15 put data to specific resources, and I've linked to those in the teacher's notes. 0:19 A very popular tool in the arena of API manual testing is named Postman. 0:23 We'll get that installed here in a few. 0:27 Since our application is HAL, or 0:29 Hypermedia Application Language compliant, we can also use a HAL browser. 0:31 There is a very nice packaged up version that we'll take a look at. 0:36 It's pretty amazing. 0:39 Let's go explore. 0:40 Okay, so Postman is a Chrome extension and 0:42 I've put its installation instructions in the teachers notes. 0:45 Now this is what it looks like currently. 0:47 Yours might look a little bit different, but 0:49 don't worry, this tool just keeps getting better. 0:51 If things work a little bit different, I guarantee it's for the better. 0:53 So Postman does an amazing job of keeping track of 0:56 what you do history wise over here. 1:00 And it really helps to produce valid queries. 1:03 So just to show it off, let's take a quick look at courses. 1:05 So I'm gonna go to http://localhost:8080 and go to courses. 1:09 And I'm going to send a GET request. 1:16 So we're gonna press Send, awesome. 1:19 So here's the response. 1:21 And one of the really cool things about this is if you click, 1:23 you can click these links. 1:26 And what it will do is it will make a new tab up here, and 1:27 it will do the next thing that you want to do. 1:30 It automatically prefilled that for me, so we can click Send, so 1:32 we can kind of navigate through the API. 1:35 Pretty nice, right? 1:37 So let's go ahead, and this is this course here, Groovy for Neckbeards. 1:38 Let's go ahead and write a review for this course. 1:44 This is course number five here. 1:46 So the way that we add a review is we go to our reviews collection, which, 1:48 remember, is that /reviews. 1:53 And we want to make a new one so we're gonna to make a POST, okay? 1:55 And we're gonna send, in the body, we're gonna send the review actually so 2:00 we want raw, and we're gonna send application JSON, right? 2:04 That's the way that our REST API has decided that it's gonna communicate. 2:07 So we're gonna choose proper JSON, and we're gonna say reading is, 2:11 let's see, Groovy for Neckbeards is a four. 2:16 And the description we'll give a proper 2:20 neckbeard description is Well, actually. 2:24 Right, so in order to send what course we're talking about, 2:30 the way that Spring Hedo us works out of the gate is you 2:36 pass either the URL for the course resource or he URI. 2:40 So let's go ahead and let's pass the URI. 2:44 So we're gonna say that the course, 2:46 that's the course property that's on there, is /courses/5. 2:50 That's gonna use that URL to find exactly what we were talking about, right, so 2:56 that's the link that we're passing around. 2:59 Again, remember this is down here. 3:02 courses/5, courses/5. 3:03 So we're gonna add that. 3:06 So we're doing a POST, and when I switched that to JSON application, 3:07 look what it did. 3:10 It set our request header to say Content-Type application/json. 3:10 Awesome, did that for us. 3:14 Okay, so then let's go ahead and click Send. 3:17 And we got a bad request, which is good, to see an error like this. 3:20 Look, I got a bad JSON. 3:25 Bad, bad JSON. 3:26 There we go, let's try this one more time. 3:28 I'm gonna click send, and boom, 201 created. 3:30 And you'll see here that it's 4, and we'll actually, and look, it's got a new ID. 3:34 So there's a reviews/102, and you can go see that. 3:38 And if you go to reviews/102 by clicking it, I'm gonna click send again, 3:40 you see that it says, well, actually, and here is the course that was reviewed. 3:44 Awesome, so if we come and do Send, and see, 3:47 we can navigate all the way around our API. 3:50 You know what, I saw something when I was looking at this reviews list here. 3:54 I saw something. 3:59 Down here it says this this profile link here. 4:02 So it says profile/reviews. 4:04 So I'm gonna ahead and click that, cuz why not? 4:07 Cuz we can navigate around. 4:10 Now let's see what this is. 4:11 So this is ALPS, it's what is known as ALPS, application level profile semantics. 4:13 And it's a standard format that helps you to document your application in 4:19 a standard way. 4:23 And we have one up here for courses as well. 4:24 So if you go to profile/courses, so this is the course representation and 4:27 it's got these different descriptors and it's a format. 4:31 It's a standard format. 4:34 And there's tools that consume this and generate documentation. 4:36 Even live sites that let you interact with your API live. 4:40 Now this is just one of several standards. 4:43 So if you want to make this thing a little bit more specific to what were pushing out 4:45 if we wanted to customize this at all, I bet you can guess what we would do, right? 4:50 So what we would do was, we would add a properties file and 4:54 do some configuration there. 4:58 So these are actually in another configuration file, 5:00 much like application properties, so if we make a new file in resources here, 5:03 And we call it rest-messages.properties. 5:11 And the way that this works is you do 5:18 rest.description and then the name of the entity, which, 5:23 in our case, we wanna change that course page, right. 5:27 So we'll say course. 5:29 Now at this top level, what we wanna do is we wanna say course= so 5:30 we can explain what this is here. 5:35 So this is a collection of online courses. 5:38 So if somebody was looking at this, they would know what we meant by course, 5:42 like it's not a meal. 5:45 It's a collection of online courses, because that could still be misconstrued. 5:47 So let's go ahead and do this. 5:51 So we can say specifically the course.title. 5:53 We can help explain a little bit more, document the name of the course. 5:59 And then let's do rest.description.course.url. 6:04 And this is link of where to find the course online. 6:12 So now let's go ahead, let's restart our server. 6:20 Let's go, make sure that that updated our ALPS. 6:28 So when you click Send again, we're on profile courses. 6:31 And boom, here it's talking about, 6:36 now we have documentation that we're providing for our API. 6:38 Pretty slick, right? 6:41 And again, there's tools that read this, but not everybody reads ALPS. 6:43 There's another standard called JSON schema, and 6:46 it would be nice if we did that too, right? 6:49 So we could probably write that, but before you do that, I know, 6:51 this is getting a little ridiculous. 6:54 It can generate that too. 6:56 So simply by adding an accept header in here. 6:57 If we come up to our headers here and we add Accept, and we say application, 7:02 this is not in the dropdown, cuz it's sort of a new thing, schema+json. 7:07 And when we refresh, it's gonna change to match this other standard and 7:13 we didn't have to write that. 7:18 And we didn't even have to research it, and look, it's producing and 7:20 it's using our description. 7:23 Super powerful. 7:25 So cool, another standard that we didn't have to research, adhere to, and/or test. 7:26 Again, producing these is not what our client is paying us for, right? 7:32 Our course review client, they're not paying for this. 7:35 But I am so glad that the Spring data REST team has taken care of this for us so 7:38 that we don't need to write it, we can focus on the business logic. 7:42 Now more on this and other formats in the teacher's notes. 7:46 Speaking of other formats, why don't we take a look 7:48 at the awesome tool Howl Browser, right after this quick break. 7:51
You need to sign up for Treehouse in order to download course files.Sign up