In this homework exercise, you will use Postman to make API calls to your FastAPI app.
Postman is an API client. It lets you send requests such as GET, POST, PATCH, and DELETE without writing code.
- How to download Postman.
- How to send a
GETrequest. - How to send a
POSTrequest with JSON. - How to send a
PATCHrequest. - How to send a
DELETErequest. - How to read the response status code and JSON body.
- Open the official Postman download page:
https://www.postman.com/downloads/
Use the official Postman site only.
- Download the desktop app for your operating system.
Postman supports Windows, macOS, and Linux. The official installation guide says to download the latest desktop app from the Postman download page and choose the option for your operating system.
For installation steps specific to your system, follow the official Postman installation guide.
Use the desktop app for this homework so you can send requests directly to your local API at 127.0.0.1.
- Install and open Postman.
You may be asked to create or sign in to a Postman account. Follow the screen instructions.
Watch How to Send Your First API Request in Postman, published on Postman's official YouTube channel (about 9 minutes).
Focus on creating a request, sending a GET request, and reading the JSON response. The video demonstrates a different API; for this homework, use your Notes API and the URLs below.
The video uses an earlier Postman interface, so some buttons may look different. The current official quick-start guide provides an up-to-date reference.
-
Open your
week2-notes-crudproject in VS Code. -
Activate your virtual environment.
-
Run the API:
uvicorn main:app --reloadKeep the server running while you use Postman. If the API is already running, skip the second start command. An Address already in use error means another process is using port 8000.
-
In Postman, open a new HTTP request tab using Add (the + button) in the workbench.
-
Set the method to:
GET
- Enter this URL:
http://127.0.0.1:8000/notes
- Click Send.
Expect status 200 and a JSON list. If there are no notes yet, you may see:
[]-
Create a new request.
-
Set the method to:
POST
- Enter this URL:
http://127.0.0.1:8000/notes
-
Open the Body tab.
-
Select raw.
-
Change the body type to JSON.
-
Add this JSON:
{
"title": "Postman note",
"text": "I created this note using Postman."
}- Click Send.
Expect status 201 and a response with an id, title, and text. Copy the returned id for the next requests. IDs do not restart at 1 when notes are deleted, so do not assume your new note has ID 1.
-
Create a new request.
-
Set the method to:
PATCH
- Enter this URL:
http://127.0.0.1:8000/notes/1
Replace 1 with the exact id returned by your POST request.
-
Open the Body tab.
-
Select raw and JSON.
-
Add this JSON:
{
"title": "Updated from Postman"
}- Click Send.
Expect status 200 and the updated note. The original text should remain unchanged because you sent only a title.
-
Create a new request.
-
Set the method to:
DELETE
- Enter this URL:
http://127.0.0.1:8000/notes/1
Replace 1 with the exact id returned by your POST request.
- Click Send.
Expect status 200 and:
{"message":"Note deleted"}- Send
GET /notesagain to check that this note is gone. Other notes may still be listed. Also request the deleted ID withGET /notes/{note_id}; expect 404 and{"detail":"Note not found"}.
-
Go back to the VS Code terminal.
-
Stop the server with:
Ctrl + C
- Connection refused / could not send request: check that Uvicorn is running and the URL uses
http://127.0.0.1:8000. 422after POST: check that the body is set to raw JSON and contains bothtitleandtextas strings.404after PATCH or DELETE: use the ID from your POST response and check that the note has not already been deleted.
Before you finish, make sure:
- Postman is installed.
GET /notesworks in Postman.POST /notescreates a note.PATCH /notes/{note_id}updates a note.DELETE /notes/{note_id}deletes a note.- You can find the response status code in Postman.
Homework 2 is complete. Follow the homework submission instructions to share your public repository in Teams for feedback, then complete the Weekend Activity: Cloud and AI.