RESTful and HTTP APIs in Pyramid Transcripts
Chapter: What is REST?
Lecture: HTTP verbs

Login or purchase this course to watch this video and the rest of the course contents.
0:01 When building http services, it's really important to make proper use of the http verbs.
0:07 Now, there are many esoteric verbs, but the four that appear all the time in restful or http services are get, post, put and delete.
0:17 So let's talk about those quickly and then we'll see an example. So get is the one that happens by default, if you go and type a url into your browser
0:25 and you hit enter, that's a get request, right, just send me the resource there. And the idea is that this should be basically read only,
0:33 it should have no other effect other than retrieving the data. You don't want to initialize the service this way,
0:39 you don't want to require that you do a get request to something before you can do something else, this is just a read this property type of thing.
0:47 And notice that I have it marked as item potent, and what that means is if I call it once, if I do a get request to some url certain parameters,
0:56 then I call it again and again and again, it should have no effect, the second, third and fourth time.
1:02 So if I apply this operation more than once, it shouldn't change it, that's item potent. And item potent is super important for services
1:10 because the item potent verbs are casual, if you do a request and it goes to some kind of proxy server
1:16 or even cashing in your browser, it can see that you did the get request to this and maybe we don't need to run this operation again,
1:24 we can just return the cash local copy, because we know it's item potent we know it should have no effect.
1:30 Now, the other popular one that you see all the time in web pages and stuff is post. If you submit a form that typically submits something as a post
1:40 and the idea with these post operations is that there is some kind of body submitted to the server
1:46 maybe this is form and coded data, key value, key value, key value like you might have an HTML form, it is also a very common for that to be json,
1:52 but however it's represented, you basically go into the server and saying I would like you to accept this new piece of data,
1:59 maybe this new book, I'm trying to create a book in the service or a new user or something like that, and then the service is supposed to respond
2:07 and say I have created it and you can find it over here, this is the one operation of the popular ones that's not item potent.
2:15 If I say create a new book and I give it some information and I ask you to create a book again,
2:21 chances are you now have two books with the same title or something like that,
2:24 unless you have good validation, so this one is not item potent and that's important. And the idea here is, you're going to submit this book,
2:31 but you don't really know like what the url or the primary key or whatever it's going to be,
2:36 just hey here's a new book create it and tell me where it goes. Similar to this, but if you know where it's going to go,
2:41 like if you're creating a cms say, and like I want to create a new page in this site
2:46 and the url is going to be the this, well possibly we would do a put instead of a post and we put it to that address to say create this page here
2:55 and so it's much like a post, you submit a body and the server except it and creates a thing,
3:01 but you're telling the server you're letting the client decide what is the id basically. And finally, if it makes sense for an item to be deleted
3:08 so in our book store we want to delete the book or maybe delete a comment or something like that,
3:14 we could do an http delete operation against some resource and just like if we put the same data to the same url over and over,
3:21 it's still the same data, the same url, deleting the thing one or a hundred times, it's still gone.
3:26 So these other two put and delete operations are also item potent.


Talk Python's Mastodon Michael Kennedy's Mastodon