3.3 Installing and Using Postman
As you begin to create your REST API, you are going to want to test each piece so that you can be sure that everything is working as you want it to. In this lesson, I'll introduce you to a very helpful tool that is built specifically for testing APIs: Postman.
1.Introduction2 lessons, 05:46
2.Getting Started4 lessons, 29:58
3.Building the API11 lessons, 1:16:10
4.Conclusion1 lesson, 01:37
3.3 Installing and Using Postman
As I mentioned in the last lesson, it's pretty simple to just use a simple browser to initiate requests into your API if you're just doing get requests. Those are pretty simple. But when it comes to doing things like post, put and delete, you need a little bit more of a sophisticated tool. Now, you can do things like cURL if you would like to, but I have really, over the last several years, started to use a tool called Postman quite a bit. I'm a big fan, it works pretty well. I use it personally, I use it professionally. So it's very nice. And so, I wanna show it you a little bit here so you can see how to use it. Not only for this particular course, but also in some of your projects going forward if you want to create APIs and then ultimately test them in any sort of really sophisticated way. So in order to get the tool, which is free, you can simply head over to getpostman dot com. You'll get to this page right here. And then, you can go ahead and you click Download the app. Now, if you have used Postman in the past, and I have used this in previous courses before as well, things have changed a little bit if you haven't looked at it in a while. It used to be just a tool that was a Chrome extension that you could input just put it right into Chrome and you could use it directly in Chrome. And then became a chrome app, so that was kind of cool, too. But now, its kind of becoming its own native app. So if you have a Chrome extension or a Chrome app version of it, it may not work forever. It does the work, you can still use it that way, but it's gonna be going away. It's kinda deprecated, it's kinda being sunset for that. So if you haven't gotten the latest version that's actually a native app, I highly recommend you do that sooner rather than later. So once you get to the app section here, you can come down, you'll see the native apps. You can select whatever you have for your MAC, for Windows, for Linux. Go ahead and click the download button for whatever platform you need. Go through wherever the installation process is that you need. And then, eventually, you'll wind up with something that looks a little bit like this once you started up. Now, it'll ask you to login or create a new account if you don't already have one. It's very simple, it's free, once again. You can sign in with Google or do whatever you want. But so, right now, this is the basic shell of the application. So what I want to do is I want to begin by creating or initiating a request to go to my application. So you already saw me do this through Chrome, but I'm going to show you how you can do it through Postman as well. So I'm going to come into the tab in here, and I can create as many tabs as I want to. But in this section here, I want to be able to create a request that I want to send out. And in this case, I can specify what type of request. I can do any sort of HTTP request that I want. In this case, I do want to start off with a get. And I'm gonna say I want to go to http slash slash local host port 3,000. And if I do that, and I come over to the right-hand side, and I hit Send, you're gonna see I'm gonna get a response back Welcome to My Koa App. All right, so we can see that that still works, even through Postman. I can say I wanna get the third, or I wanna actually go to Tasks. And let's go ahead and hit Send there. I'm gonna get returns all tasks. So you can see everything still works the way it did before. I'll say slash three. I'm gonna get the tasks with ID 3. But now, I want to try a post. So the way that we do that is we come into Post. And this is gonna make more sense when we actually have something to post or we want to create a new task. And that's coming soon, I promise. But I just want to show you how the tool works. So now, I have created a post handler for slash tasks. So in this case, I'm just going to do a post. I'm gonna hit Send. And you're going to see I send back a response Creates a new task. Now, this is not a traditional way to do a post. You're typically going to do a post to an endpoint, and you're gonna have a body. And I'm gonna show you how we handle that and what the body's gonna look like when we get into that particular part of the course, when we're in that particular lesson. But for now, you're gonna wind up going into body. And the way that I typically like to do it, is I like to create a raw request where we're gonna send JSON data into our application, say create a test that looks like this. And so, we're gonna get to that. So that's the way you would send a post. You can do the same for a put, as you can see here. So I'll go ahead and hit Send. Sorry, for a put, we do have to have an ID. So I'll say put task one. We wanna update a task with ID1. And then finally, for the delete, we'll do the same thing. This is going to delete task with ID1. And the cool thing about using Postman to do this stuff, is once you start doing these requests, it's gonna keep a history of it. So I can go back and say yeah, how did it work if I just got the get on the tasks? So it's gonna save that. And if I were to click on that, it's gonna take me right back to where I was. I can go ahead and hit Send, and I can get that response back and see how it's still working. So this is kind of nice. So if you are interested in using a tool like this to test out your API as you're building, whether you're using it for or not, I would highly recommend you taking a look at the Postman tool and see how it fits into your workflow. So now that we've kinda gone through the process, and you can see now that I'm logging all those requests, the post, the puts, the deletes, the gets and everything. So now, I'm able to do all those things. Now, I just need to be able to handle actual requests for actual tasks. So let's start to move in that direction for the next part of the course.