restful apis with herman radtke

16
HTTP Methods How They Relate to RESTful API's

Upload: venturaphp

Post on 13-Jul-2015

154 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: RESTful APIs with Herman Radtke

HTTP MethodsHow They Relate to RESTful API's

Page 2: RESTful APIs with Herman Radtke

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: RESTful APIs with Herman Radtke

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: RESTful APIs with Herman Radtke

Why?

REST is an architectural style

Not satisfied with the existing explanations

Page 5: RESTful APIs with Herman Radtke

GET vs POST

Do we actually know the differences?

Page 6: RESTful APIs with Herman Radtke

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 7: RESTful APIs with Herman Radtke

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 8: RESTful APIs with Herman Radtke

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 9: RESTful APIs with Herman Radtke

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 10: RESTful APIs with Herman Radtke

Create Using POST

Page 11: RESTful APIs with Herman Radtke

Create Using PUT

Page 12: RESTful APIs with Herman Radtke

Update Using POST 1/2

Page 13: RESTful APIs with Herman Radtke

Update Using POST 2/2

Page 14: RESTful APIs with Herman Radtke

Update Using PUT

Page 15: RESTful APIs with Herman Radtke

Other HTTP Methods

PATCH

DELETE

HEAD

OPTIONS

Page 16: RESTful APIs with Herman Radtke

Additional Resources

RFC 2616 Method Definitions - http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

#rest on freenode

My twitter - @hermanradtke