Postman
Contributors: Alanna Zhou
Last updated
Contributors: Alanna Zhou
Last updated
Highly recommend you install Postman as soon as the course starts! It will be crucial to assignments and practically any backend dev-ing.
If you hit an endpoint in your browser, the best you can do is hit endpoints that are just GET
requests (see the section below on how to hit an endpoint). There's no easy way for you to test parts of your backend API that handle POST
and DELETE
requests -- so how do you know if you are responding in the way that you coded and expected? Use Postman!
Postman lets you do all of these things with a super helpful user interface. You can even organize all of the endpoints your testing into folders and workspaces, as well as share them with whoever is collaborating with you on a project!
When you run your code locally (aka on local host), your endpoint at port 5000
can be reachable at all of these options:
This is because 0.0.0.0
, 127.0.0.1
, and localhost
all mean you're running off of local host! You can read more about the differences on this stack exchange post.
If you can't hit your endpoint, ensure that you are also hitting the right port that your code is running on! This is usually declared somewhere at the bottom of your app.py
:
There's a difference between http
and https
, so make sure you are hitting http
!
Select GET
from the dropdown to the left of the Enter request URL
input text field bar
Input the endpoint receiving the GET
request into the text field bar
Click the blue send
button
Postman will now show you either your successful JSON
response at the bottom, or some errors for you to fix
GET
Query ParametersGET requests can also have parameters, and there are two ways to hit an endpoint with parameters:
GET
parameters manually into the input text field barwhere key1
and key2
are the names of your parameters, and value1
and value2
are the corresponding values (you can have as many as you want, but this example only has two key-value pairs).
For example, if I'm designing backend that returns some information about a student given their first name, last name, and age, I could type this URL into the text field input bar:
GET
parameters into the table and let Postman automatically fill in your URLJust type away under Params
(select this option in the banner under the URL) and the checkboxes will automatically be checked and your URL will automatically have the params filled in!
Select POST
from the dropdown to the left of the Enter request URL
input text field bar
Input the endpoint receiving the POST
request into the text field bar
Click on Body
in the banner right below (next to Headers
and Pre-request Script
)
Select raw
Select JSON
from the dropdown to the right of raw
Type in your POST
request body in JSON
format
Click the blue send
button
Postman will now show you either your successful JSON
response at the bottom, or some errors for you to fix
Here's an example of what a POST
request could look like, with the { "first" ... "true" }
information being the POST
request body written in JSON
format.
Note that JSON
can take in strings, integers, and booleans.