Consuming HTTP Services in Python Transcripts
Chapter: Consuming RESTful HTTP services
Lecture: The HTTP verb meanings

Login or purchase this course to watch this video and the rest of the course contents.
0:02 Let's look at these http verbs in a couple of ways,
0:05 here we are going to play around with just a generic example and then later,
0:08 we are going to go look at a public very thought out API.
0:12 So imagine we have some service running that
0:16 and it has a certain number of resources and its specifications,
0:19 so users and then users/ some kind of id based on what you are looking for
0:25 and maybe even /id/picture to get their picture.
0:28 also projects and project details, so project 11 and even files about them,
0:32 so we might issue a get request against projects
0:36 and that would return let's just say there is always going to be json
0:38 and give us a json representation of maybe the id and title of every project
0:43 that you have access to.
0:46 Then maybe in there somewhere is project 11
0:48 and that is the one you want details at so you could do a get against project 11.
0:51 Now, maybe you don't have any projects, you want to create one,
0:55 well typically the way these http services would do that
0:58 is we would do an http post against /project
1:04 and we'll see that that would tell the service hey I would like to create a project
1:08 and the body of that post, the data in that post would be the required details
1:12 to create a service, maybe not everything about it, but things like its name,
1:15 who the owners are, stuff like that.
1:17 Similarly, if we wanted to update a user, we might go to /users,
1:21 we know we want to update user 42, we need to do an http put against that,
1:26 so you see we combine the verbs with the resources to get all the behaviors
1:30 that you are looking for, not all services work this way,
1:34 put and delete is becoming increasingly popular people use these,
1:38 but get and post those are the mains of http services.
1:42 So, how do I know that doing a put against users/42 is supposed to update it
1:49 and doing a post against users should create a new user in the first place.
1:54 Well, if we are following these http services
1:57 and we are trying to use these verbs to have these meanings,
2:00 we just have to look at the actual definition of get, post, put and delete.
2:03 So if we go over to the Wikipedia entry for the hypertext protocol
2:07 we'll see we have four verbs that I pulled out here
2:12 there are actually many more patch and whatnot that could be used
2:15 but these are the real main players in these services,
2:18 and notice, only get is what is called item potent.
2:21 Item potent means that if you apply it one time, something may happen,
2:25 if you apply it five more times, it will be exactly as if you've only applied it once,
2:30 so basically it means you can apply it to itself as many times as you want,
2:34 whereas post, put and delete applying them a second time
2:38 might actually have a separate meaning, okay.
2:41 So if we look at get, it should only retrieve the data and basically have no other effect,
2:46 if we look at post, this should tell the server to accept the entity enclosed in the body,
2:51 and create as a subordinate, so if I want to create a user with id 42,
2:55 I would do a post of that user to /users and then we theoretically have
3:00 /user/42 was created as part of that action
3:04 whereas put is supposed to replace or update the entity at that location,
3:09 so do a put to /user/42 should update user 42.
3:13 And finally, doing a delete against user/42 well, you can bet that user is gone.