groking http methods
DESCRIPTION
We have probably all heard of REST. It is currently the popular way to create APIs for internal and/or external use. Virtually all RESTful API’s are built on top of HTTP. Thus, it is important to understand how the different HTTP methods work. They are key to creating a solid RESTful API and offer so much more than simple CRUD. We will be taking a deep-dive into the HTTP methods and coming away with a solid understanding of they function.TRANSCRIPT
![Page 1: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/1.jpg)
HTTP MethodsHow They Relate to RESTful API's
![Page 2: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/2.jpg)
About Me
Herman J. Radtke III
Web Architect at HauteLookDesign the RESTful API
Writing PHP for 9 years
Maintain pecl/gearman and pecl/memcache
![Page 3: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/3.jpg)
Perspective
HauteLook's API is for internal useVery few restrictions on designExample: Netflix
Many companies have an external APIConcerned with how the design affects other clients (ex: flash)Examples: Twilio, Jira, Facebook
![Page 4: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/4.jpg)
Why?
REST is an architectural style
![Page 5: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/5.jpg)
RESTful Language
HTTP Methods are verbsURLs are nouns
Example: GET /users/1234
![Page 6: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/6.jpg)
Logging Out
POST /logoutPOST is for createMeans: Create a logout resource
DELETE /logoutDELETE is to remove a resourceMeans: Delete a logout resource
DELETE /credentials
![Page 7: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/7.jpg)
GET vs POST
Do we actually know the differences?
![Page 8: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/8.jpg)
GET vs POST
I ask every interviewee this question.
Common answers:GET does not send a body in the request
POST can send more data
POST is more secure
![Page 9: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/9.jpg)
Idempotence
Idempotence means no side-effects.
This is the most important difference!GET is idempotent (safe)POST is not idempotent (unsafe)
It allows the web to scale.
![Page 10: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/10.jpg)
Improper use of GET
<a href=”/logout.php”>Logout</a>
We just broke the internetCaching proxiesBrowser "accelerator" plugins
Better to use a form with the POST method
Other example: Tracking Pixels
![Page 11: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/11.jpg)
POST vs PUT
POST is create and PUT is update, right?
Not so simpleMethods do not map to CRUDCRUD can map to the methods
Key difference?PUT is idempotent!
![Page 12: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/12.jpg)
Create Using POST
![Page 13: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/13.jpg)
Create Using PUT
![Page 14: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/14.jpg)
Update Using POST 1/2
![Page 15: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/15.jpg)
Update Using POST 2/2
![Page 16: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/16.jpg)
Update Using PUT
![Page 17: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/17.jpg)
Other HTTP Methods
PATCH
DELETE
HEAD
OPTIONS
![Page 18: Groking HTTP Methods](https://reader033.vdocument.in/reader033/viewer/2022060122/5596383c1a28abf0148b47c1/html5/thumbnails/18.jpg)
Additional Resources
RFC 2616 Method Definitions - http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
#rest on freenode
My twitter - @hermanradtke