From the course: Introducing Postman

Your first request - Postman Tutorial

From the course: Introducing Postman

Start my 1-month free trial

Your first request

- [Instructor] One of Postman's primary purposes is allowing us to craft requests to the APIs we use. Be they APIs we're actively developing or third party APIs we need to consume. Since most of our time in Postman is spent doing just that, let's make our first request against a sample API. In order to make a request of any API, we need to specify that API's URL. For our first request, we're going to hit the sample API status route, which simply responds with a message indicating that the API is listening. We'll begin by entering the base URL. Our server is running locally, and listening on port 3,000 so we'll enter HTTP local host 3,000. (keys clacking) The base URL alone isn't enough. We also need to provide a route. Everything in the sample API is routed under the slash API route, so let's append slash API to the end of the URL. We also need to specify the HTTP method for the request. When you click the dropdown arrow, you can see a list of methods available for your request. The list includes standard methods like get, post, put, and delete. But also several additional verbs used by some APIs. Postman allows us to define custom methods, but that's not something we need to do in this course. Our first request is going to be a get request, which is the default option. Let's make sure get is selected, and proceed. Postman provides a few ways to issue or send requests. First is by clicking the send button. Or pressing Command + Enter, or Control + Enter on Windows. Alternatively, we can click the dropdown arrow attached to the send button, and choose send and download. This alternative provides a convenient way to immediately save any response to a file, which can be handy when trying to capture a data set for later use. For now, we'll just use the standard action, which displays the results in the bottom panel. When the request completes, you'll see a message that echos some header values along with a message, which reads the API is listening. If you receive an error instead of the expected text, verify that the sample API is running, that you've entered the correct URL, and the get method is selected. The response body is presented under the body tab. There are three views for the response body. Pretty, raw, and preview. Pretty tries to apply basic formatting to the content when that content has a known structure. Raw shows the content exactly as it was received. And preview attempts to render the content. Preview is most useful when you want to get an idea of what an HTML document would look like in the browser. Note that when the response is an image or other non-text type, these options won't be available. Postman will simply attempt to render the content instead. When the pretty option is selected, the dropdown list next to the three display options let's us select the content type. Here we see that auto is selected. Postman does a decent job of automatically detecting the content type, but should you need to override it, this is where you should do so. In addition to displaying the response body, Postman can also display cookies returned from the server, and the full list of response headers. Our sample API doesn't use cookies, so the cookies tab will be empty, aside from the no cookie for you message. Clicking over to the headers tab reveals all of the headers provided by the server for the response. Our sample API provides only a few basic headers including content type, content length, and X powered by. Finally, we can also see the response status code, request time, and response size. In this case, the server responded with status 200 indicating the request was successful. It took 12 milliseconds, and contains 296 bytes. So hurray! We've made our first API request in Postman. You got to see the sample API respond with a message that it was listening. I'm making a little light of it, but even that first request covered a lot of ground, by introducing how to enter the destination URL, specify the HTTP method, and inspect the results. Those things are the basis for every API request made in Postman.

Contents