You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
In Lec99, the HTTP response of PUT is not fully correctly dealt with. According to this: https://httpwg.org/specs/rfc7231.html, PUT should return 201, when new resource has been created.
(Also, added error handling similarly to the post() method)
So, I think implementation of put() should be appended with the HTTP response code handling, like this:
def put(self, name):
data = Item.parser.parse_args()
item = ItemModel.find_by_name(name)
# if item with name doesn't exist, we create it
if item is None:
item = ItemModel(name, **data)
http_status_code = 200
else:
item.price = data["price"]
http_status_code = 201
try:
item.save_to_db()
except:
return {"message": "An error occurred upserting the item."}, 500
return item.json(), http_status_code
Best,
Csb
The text was updated successfully, but these errors were encountered:
rest-apis-flask-python/section6/resources/item.py
Lines 48 to 60 in 3380640
Hi,
In Lec99, the HTTP response of PUT is not fully correctly dealt with. According to this: https://httpwg.org/specs/rfc7231.html, PUT should return 201, when new resource has been created.
(Also, added error handling similarly to the post() method)
So, I think implementation of put() should be appended with the HTTP response code handling, like this:
Best,
Csb
The text was updated successfully, but these errors were encountered: