On this page:
Update a sighting: a tutorial
This tutorial should take you about 20 minutes to complete.
Before you begin
- Make sure you’ve set up your environment.
- If it’s not already running, start the Orca Sightings service with json-server.
How to update the full sighting entry
Use the PUT method to update a full sighting entry.
Step 1: list all sightings to find the id of the sighting you want to update
You can use cURL or Postman to submit a PUT request.
To use cURL:
- Open a new terminal window.
- List all sightings. Notice the sighting entry with an
idof2.
...
{
"id": 2,
"user_id": 3,
"pod": "T49A",
"time": "2025-05-01T19:00",
"location": "Patos Island"
},
...
To use Postman:
- Open Postman.
- List all sightings. Notice the sighting entry with an
idof2.
...
{
"id": 2,
"user_id": 3,
"pod": "T49A",
"time": "2025-05-01T19:00",
"location": "Patos Island"
},
...
Step 2: replace the entire entry using the PUT method
To use cURL:
- Include that information in a cURL request, changing the pod to
unknown. Don’t include theidin the-dfield. Instead, include that number at the end of the URL. This is the endpoint.
curl -X PUT \
-H "Content-Type: application/json" \
-d '{
"user_id": 3,
"pod": "unknown",
"time": "2025-05-01T19:00",
"location": "Patos Island"
}' \
http://localhost:3000/sightings/2
In the cURL command, -X denotes the method to use, -H indicates the header to use, and -d specifies the data to include.
The user_id isn’t the same as the id. The latter refers to the sighting ID, which you add to the end of the URL. The former pairs the sighting with the user who reported it.
The output should look like the following:
{
"user_id": 3,
"pod": "unknown",
"time": "2025-05-01T19:00",
"location": "Patos Island"
"id": 2,
}
To use Postman:
- In Postman’s main panel on the right, toward the top, select PUT.
- Add the following content to the URL text box next to PUT:
http://localhost:3000/sightings/2. This indicates that you’ll replace the information for the user that has an ID of 2. - If you don’t already have the header designated, choose Headers and specify Content-Type: application/json.
- Choose Body and specify Raw.
- Copy the following example code that changes the pod to
unknown.Paste this into Postman’s Body text box.
{
"user_id": 3,
"pod": "unknown",
"time": "2025-05-01T19:00",
"location": "Patos Island"
}
Notice that you don’t need the ID. Enter it in Postman’s URL parameters. You must remove the trailing comma in the last key-value pair.
Notice that the response includes the entire entry details with the ID.
{
"user_id": 3,
"pod": "unknown",
"time": "2025-05-01T19:00",
"location": "Patos Island"
"id": 2,
}
How to update only part of the entry
Update just a part of the user entry using the PATCH method. Choose the same sighting as in the previous example with an id of 2. You’ll update just the time.
To use cURL:
Send a request using cURL with the following command:
curl -X PATCH \
-H "Content-Type: application/json" \
-d '{ "time": "2025-05-01T08:00" }' \
http://localhost:3000/sightings/2
Notice that the time value, which follows the T is now 8:00 AM: 08:00.
For a full description of the time value, refer to ISO 8601 format.
Notice that the response includes the entire entry details with the updated time.
{
"user_id": 3,
"pod": "unknown",
"time": "2025-05-01T08:00",
"location": "Patos Island"
"id": 2,
}
To use Postman:
- In Postman’s main panel on the right, toward the top, select PATCH.
- Add the following content to the URL text box next to PATCH:
http://localhost:3000/sightings/2. This indicates that you’ll update some information for the sighting that has an ID of2. - If you don’t already have the header designated, choose Headers and specify Content-Type: application/json.
- Choose Body and specify Raw.
- Copy the following example code that changes the time
...T19:00to 8:00 AM:...T08:00. Paste the following into Postman’s Body text box.
{
"time": "2025-05-01T08:00"
}
Notice that the response includes the entire entry details with the updated time.
{
"user_id": 3,
"pod": "unknown",
"time": "2025-05-01T08:00",
"location": "Patos Island"
"id": 2,
}
You’ve completed this tutorial. Next try other tutorials or refer to the PUT and PATCH reference topics.