21
Can you finally REST?! meet.php # 13 by: Max Małecki @emgiezet

MeetPHP # 13 - Can you finally rest

Embed Size (px)

DESCRIPTION

How to not ruin life of developers. About basic rules of RESTful API, documentation and tools. Repo from live coding: https://github.com/emgiezet/meetphp13-rest Read More: http://shishkin.github.io/presentations/rest/ http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http http://martinfowler.com/articles/richardsonMaturityModel.html http://timelessrepo.com/haters-gonna-hateoas http://www.slideshare.net/kifahibrahim/symfony2-as-an-api https://speakerdeck.com/gordalina/rest-apis-made-easy-with-symfony2

Citation preview

Page 1: MeetPHP # 13 - Can you finally rest

Can you finally REST?!

meet.php # 13by: Max Małecki @emgiezet

Page 2: MeetPHP # 13 - Can you finally rest

Cool developers:

● Mobile developers● Node.js developers● Ruby developers

Page 3: MeetPHP # 13 - Can you finally rest

Can I be as cool as they are?

You write APIs for them. Cool developers can't live without you!

Page 4: MeetPHP # 13 - Can you finally rest

7 sins of your API

● What makes you uncool?● Why „cool“ developers hates you?

Page 5: MeetPHP # 13 - Can you finally rest

0. Lack of design

Page 6: MeetPHP # 13 - Can you finally rest

1. Session Management

● RESTful – means stateless● To authorize & authenticate use

– oAuth v2– Wsse

Page 7: MeetPHP # 13 - Can you finally rest

2. Content type constraints

GET /api/dogs.json – 200

GET /api/dogs.xml – 404

● Retrun a response in a format defined in the headers of a request:

GET /api/dogs/123

Accept:

application/vnd.example+xml,

application/xml,

application/json

Accept-Language: de, fr, en

Page 8: MeetPHP # 13 - Can you finally rest

3. Api url's

/api/dogs?id=123

● Instead use uri templates

/api/dogs/123● Get parameters are good for

filtering

/api/dogs?color=black

Page 9: MeetPHP # 13 - Can you finally rest

3. Avoidance of HTTP Methods

/api/dogs/show GET /api/dogs

POST /api/dogs/api/dogs/new

Page 10: MeetPHP # 13 - Can you finally rest

4. Complexity

● Make it simple and universal

Page 11: MeetPHP # 13 - Can you finally rest

5. Lack of documentation

● If you got documentation in PDF, be sure that something is wrong.

Page 12: MeetPHP # 13 - Can you finally rest

6. Api is not cacheable

● Do you know:– varnish?– haproxy?

● So design your API to be cacheable

● PHP is not super fast consider the CACHE!

Page 13: MeetPHP # 13 - Can you finally rest

Quick tips

● Test your API – TTD is not that hard.

● Make sandbox for vendor developers

● Please, oh please use serialization

Page 14: MeetPHP # 13 - Can you finally rest

Richardson REST maturity model

● Level 0 - Swamp of POX ● Level 1 - Resources

● Level 3 - Hypermedia controls● Level 2 - HTTP verbs

Page 15: MeetPHP # 13 - Can you finally rest

Richardson Model in Symfony2

● Level 0 & Level 1 & Level 2:– FOSRestBundle– NelmioAPIDocBundle

● Authentication:– FOSOAuthServerBundle

● Level 3:– BazingaHateoasBundle

Page 16: MeetPHP # 13 - Can you finally rest

Live Code

Page 17: MeetPHP # 13 - Can you finally rest

You want that code?

Page 18: MeetPHP # 13 - Can you finally rest

Questions?

Page 19: MeetPHP # 13 - Can you finally rest

Want more?

● http://shishkin.github.io/presentations/rest/● http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-res

t-or-http● http://martinfowler.com/articles/richardsonMaturityModel.html● http://timelessrepo.com/haters-gonna-hateoas● http://www.slideshare.net/kifahibrahim/symfony2-as-an-api● https://speakerdeck.com/gordalina/rest-apis-made-easy-with-symfony2

Page 20: MeetPHP # 13 - Can you finally rest

My Question:

Explain the HATEOAS acronym

Hypertext As The Engine Of Application State

Page 21: MeetPHP # 13 - Can you finally rest

Thank you!

You're cool developer?Now you can finally REST!