Download - MeetPHP # 13 - Can you finally rest
![Page 1: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/1.jpg)
Can you finally REST?!
meet.php # 13by: Max Małecki @emgiezet
![Page 2: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/2.jpg)
Cool developers:
● Mobile developers● Node.js developers● Ruby developers
![Page 3: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/3.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/4.jpg)
7 sins of your API
● What makes you uncool?● Why „cool“ developers hates you?
![Page 5: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/5.jpg)
0. Lack of design
![Page 6: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/6.jpg)
1. Session Management
● RESTful – means stateless● To authorize & authenticate use
– oAuth v2– Wsse
![Page 7: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/7.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/8.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/9.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/10.jpg)
4. Complexity
● Make it simple and universal
![Page 11: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/11.jpg)
5. Lack of documentation
● If you got documentation in PDF, be sure that something is wrong.
![Page 12: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/12.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/13.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/14.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/15.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/16.jpg)
Live Code
![Page 17: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/17.jpg)
You want that code?
![Page 18: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/18.jpg)
Questions?
![Page 19: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/19.jpg)
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](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/20.jpg)
My Question:
Explain the HATEOAS acronym
Hypertext As The Engine Of Application State
![Page 21: MeetPHP # 13 - Can you finally rest](https://reader033.vdocuments.net/reader033/viewer/2022051515/54c69a8e4a795917528b457e/html5/thumbnails/21.jpg)
Thank you!
You're cool developer?Now you can finally REST!