Using Postman to Test Routes2:11 with Treasure Porth
Postman is an application that will allow us to send a variety of requests to our API so that we can write endpoints to create, update and delete quotes.
[MUSIC] 0:00 By default, browsers send GET requests, which makes them easy to test. 0:05 Just hop into a browser and send a request to an endpoint. 0:08 If you get back the information you were expecting, 0:12 you know the route is working as intended. 0:14 Sending other types of request from the browser, like POST or DELETE, 0:17 can be a little trickier. 0:20 Postman is an application that will allow us to send a variety of requests 0:21 to our API so that we can write endpoints to create, update, and delete quotes. 0:25 And then make sure our application is functioning as we expect. 0:29 Visit the link in the teacher's notes and 0:33 follow the instructions to download Postman. 0:35 After you've done that, open up Postman, and let's take a look. 0:38 If you get any pop-ups when you first open the app, go ahead and 0:41 close them out for now. 0:44 Notice here on the left side, 0:46 we have a drop-down menu containing many types of requests. 0:48 Let's stay on GET for now. 0:52 And here we type the URL that we want to send a request to. 0:53 Make sure your server is running, so I'll go back to my terminal and type npm start. 0:57 My server is already running, so that's great. 1:03 Now that the server is running, can return to Postman. 1:06 And we'll send a GET request to our application's 1:09 /quotes route, localhost:3000/quotes. 1:14 Click Send, and this area here on the bottom shows our server's response. 1:18 We've sent a GET request and we've received an array of quote objects. 1:24 Now let's try sending a GET request to a URL containing a quote ID. 1:29 Send a GET request to localhost:3000/quotes/8721. 1:33 And we receive just that specific quote object back. 1:40 Notice the status code here. 1:44 These are status codes sent by our server to inform the client of the status of 1:46 the request. 1:50 When a request is successful, Express sends a status code of 200 automatically. 1:51 We'll learn more about status codes and how to set them later on in the course. 1:56 We'll use Postman for the rest of the course to test our routes. 1:59 In the next video, 2:03 we'll write a POST route to add a new quote to our data store. 2:03 And use Postman to send data and make sure our API is working as expected. 2:07
You need to sign up for Treehouse in order to download course files.Sign up