Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ The function `update_age` in `app.py` accepts two parameters: `id` and `new_age`
person = Person.get(id)

except NotFoundError:
return "Bad request", 400
return "User not found", 404
```

Assuming we find the person, let's update their age and save the data back to Redis:
Expand All @@ -685,7 +685,7 @@ Assuming we find the person, let's update their age and save the data back to Re
Let's change Kareem Khan's age from 27 to 28:

```bash
curl --location --request POST 'http://127.0.0.1:5000/person/01FX8RMR7T60ANQTS4P9NKPKX8/age/28'
curl --location --request PUT 'http://127.0.0.1:5000/person/01FX8RMR7T60ANQTS4P9NKPKX8/age/28'
```

The server responds with `ok`.
Expand All @@ -701,7 +701,7 @@ If we know a person's ID, we can delete them from Redis without first having to
Let's delete Dan Harris, the person with ID `01FX8RMR8545RWW4DYCE5MSZA1`:

```bash
curl --location --request POST 'http://127.0.0.1:5000/person/01FX8RMR8545RWW4DYCE5MSZA1/delete'
curl --location --request DELETE 'http://127.0.0.1:5000/person/01FX8RMR8545RWW4DYCE5MSZA1'
```

The server responds with an `ok` response regardless of whether the ID provided existed in Redis.
Expand Down
6 changes: 3 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ def create_person():
return "Bad request.", 400

# Update a person's age.
@app.route("/person/<id>/age/<int:new_age>", methods=["POST"])
@app.route("/person/<id>/age/<int:new_age>", methods=["PUT"])
def update_age(id, new_age):
try:
person = Person.get(id)

except NotFoundError:
return "Bad request", 400
return "User not found", 404

person.age = new_age
person.save()
return "ok"

# Delete a person by ID.
@app.route("/person/<id>/delete", methods=["POST"])
@app.route("/person/<id>", methods=["DELETE"])
def delete_person(id):
# Delete returns 1 if the person existed and was
# deleted, or 0 if they didn't exist. For our
Expand Down