#100DaysOfWeb in Python Transcripts
Chapter: Days 9-12: API Star
Lecture: API methods: PUT and DELETE

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Alright, next our update on the Leaf car
0:02 those should be easy now.
0:05 I'll check if the car is present
0:07 so I get the car id in a new car object
0:11 or the fields we're going to modify.
0:13 Car holds the manufacturer, year, model, and VIN optionally.
0:19 So, if the car is not there, I return an error with a 404.
0:23 And if the car is there
0:25 like we did with create, I set the id
0:29 and stored an object to the car's dictionary
0:32 or in real life to the database.
0:35 And then I serialize the new object
0:38 and return to the status code two hundred.
0:41 That's all there is to it.
0:43 So, let's test this out.
0:49 Let me get car.
0:50 And I need to restart my server.
0:54 Get car fifty five, which is a Jeep.
0:57 And now we make PUT request
0:59 and in the body we put
1:03 something else on ABC, year
1:10 So, we send a put request to that same car id
1:14 and boom, here's the new object, the updated object.
1:17 Although, this is just returning the object
1:20 as I did with POST to really see.
1:22 If it's stored in the dictionary
1:23 we need to make a new GET request.
1:26 And we see the same car
1:28 so here it's not a Jeep anymore
1:29 so the change persisted, alright?
1:32 And then for the Leaf it's very similar.
1:35 So, I'm going to do the same check first.
1:40 To see if the car id that was pasting is a valid car
1:45 so look it up.
1:46 I look up the cars.
1:47 If not, I return a 404
1:49 and the lead then simply deletes it from the dictionary.
1:53 So, I can do a Dell car id.
2:01 And then return a empty dictionary
2:06 with the status code 204.
2:07 If you remember from the status codes
2:14 that's the common return code, no content.
2:21 So, that's it, that's that out.
2:26 Car fifty-five still present.
2:28 Delete.
2:30 Boom, 204 and an empty dictionary.
2:35 Let's see if it's still there.
2:37 Now it's gone. Awesome.
2:47 Gone, 404, alright, perfect.
2:49 So, now we have a full CRUD application.
2:53 We have list cars, create a car, POST
2:58 get an individual car, get update, and delete.
3:05 And this is a fully-fledged API star app.