Lesson 05
Using Postman to Test the API
Video Transcript
Welcome back. So since we'll be starting on actually building our API endpoints,
I would like us to use a REST client to facilitate our debugging of the API or testing.
I am going to use postman.com. You can download this app to test out the API.
This is a REST client that I am going to use. If you already know how to use a REST client
and you have a favorite one, you might want to skip this video.
Anyway, I am using a Mac so I download the app and after doing that, I just move the application file to the applications folder.
Then I open it. It asks, are you sure? I just click open and then it goes like this.
So I am using postman. I am just going to go here and skip signing in and take me straight to the app.
So I got all this guy right here. I don't want to show this on launch anymore.
Close this. Let me make this smaller so you can see.
Okay, so this is postman so we can test out our API endpoints.
So here we have the HTTP verb. You can choose get, post, and so on.
And you enter the URL where you want to hit.
We are going to use HTTP colon slash slash localhost 3000.
I am going to click send and right here, down here, we get the body of the response.
And right here, it says HTML. You can see the headers here.
The content type is text, HTML, care set, UTF-8, powered by express, header, and so on.
Okay, so we got a 200 okay for the response.
That's usually the default for express. We will use this HTTP status code of 200 okay if you do not specify it.
Okay, now going back to the code.
We send this guy out, but we can also send JSON if you simply send an array or an object.
For example, you send an object with some property name and some value. Let's see what we get.
I am going back to the terminal because we changed the server code, control C to kill the server,
and do node app.js again to restart it.
Now let's go back to our REST client and we're going to resend those.
Request, if you look at the body again, now we get some JSON okay.
If you see the raw one is like this, and if you want to see the pretty version, so it's formatted with spaces and annotation, click pretty right here.
Alright, so you can see the headers of the response, content type application JSON in this case, powered by express.
Anyway, going back to the body.
So it automatically does JSON there for us, so that's nice.
Going back to the atom, add text editor. You can also do an array.
Let's do an array right here, send back an array of objects.
I'm just going to duplicate this line with some other name.
I can put an ID to just to see you can have multiple properties.
Okay, so I'm going to send back, I forgot to close the array, an array of objects.
Let's restart the server again.
Go back to the REST client, postman, resend, and now look at the results.
Let's see if we can bring this up.
Click header just so we can get more space.
So we got an array of objects. This is JSON format 200k status quote.
Look at the headers, application slash JSON.
Okay, so we got our first steps in sending back JSON from the express server.
All right, so that's what we're going to do from now on.
Just send back some data using the send method.
Okay, so let's review what we did in this lesson.
This lesson we learned that the send can be used also to send an object or an array.
And they turned out to be JSON when we tested out in our postman.
That's the REST client that we downloaded to test out the API.
You can choose the H3 verb right here on the left-hand side, the URL, the endpoint of the API.
Then you click send. You're going to be able to see the body of the response.
This is the raw one, but if you want to make it better for you to see is the pretty tab.
You can see the headers in the header tab. Notice the content type application JSON.
So it's interesting to note that the express adds an X power by header with the express text.
Okay, and we got a 200k status code by default from express.
That's it for this lesson until the next one.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: