Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)

Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)

Sergey Zhuravel

May 17, 2014
Tweet

More Decks by Sergey Zhuravel

Other Decks in Programming

Transcript

  1. Full stack is dead Microservice Architecture, [...] a particular way

    of designing software applications as suites of independently deployable services http://martinfowler.com/articles/microservices.html “ ”
  2. Full stack is dead Microservice Architecture, [...] a particular way

    of designing software applications as suites of independently deployable services http://martinfowler.com/articles/microservices.html “ ” SERVICE-ORIENTED ARCHITECTURES
  3. GET vs POST “The difference is that in a GET

    request you have the parameters in the url , with a POST the parameters are in the request’s body”
  4. WAKA “A new protocol designed to match the efficiency of

    well-designed Web Applications” http://tools.ietf.org/agenda/83/slides/slides-83-httpbis-5.pdf
  5. Failover HTTP/1.1 200 OK Date: Fri, 25 Apr 2014 16:52:37

    GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding Cache-Control: stale-if-error=3600, stale-while-revalidate=6000 Age: 0 Via: 1.1 varnish X-Cache: MISS Alternate-Protocol: 443:npn-spdy/2
  6. Failover HTTP/1.1 200 OK Date: Fri, 25 Apr 2014 16:52:37

    GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding Cache-Control: stale-if-error=3600, stale-while-revalidate=6000 Age: 0 Via: 1.1 varnish X-Cache: MISS Alternate-Protocol: 443:npn-spdy/2
  7. Failover HTTP/1.1 200 OK Date: Fri, 25 Apr 2014 16:52:37

    GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding Vary: Accept-Encoding Cache-Control: stale-if-error=3600, stale-while-revalidate=6000 Age: 0 Via: 1.1 varnish X-Cache: MISS alternate-protocol: : 443:npn-spdy/2 Alternate-Protocol: 443:npn-spdy/2 cache available if the backend is down
  8. cURL is your best friend curl -X GET https://api.namshi.com/products curl

    -X POST https://api.namshi.com/order -data=”{...}” curl -X DELETE ... curl -X PATCH ...
  9. USER TAGS deleting a non-existent tag 200 or 204 or

    404? http://stackoverflow. com/questions/2342579/http-status-code- for-update-and-delete
  10. USER TAGS deleting a non-existent tag 200 or 204 or

    404? http://stackoverflow. com/questions/2342579/http-status-code- for-update-and-delete ON STACKOVERFLOW THEY’RE STILL FIGHTING http://stackoverflow.com/questions/2342579/http-status-code-for-update-and-delete
  11. The client receives a GET on /something and will let

    the API figure out what /u/something actually is
  12. “Most APIs are designed by the API provider with the

    goal of maintaining data model purity. When building an OL, be prepared to sometimes abandon purity in favor of optimizations and/or performance.” Daniel Jacobson, director of engineering for the Netflix API http://www.infoq.com/presentations/API-Revolution
  13. codebase organization one bundle for each api? one bundle for

    each application? one app for each sets of api?
  14. iFrames to the rescue! the iFrame triggers the ajax request

    on its own domain with the parameters in the message
  15. Don’t play with fire Less things to implement on every

    client and centralized implementations
  16. Don’t play with fire POST https://api.example.com/login 200 OK date: Thu,

    01 May 2014 21:52:33 GMT content-type: application/json transfer-encoding: chunked connection: close set-cookie: login=...; cache-control: no-cache { "email"=>"[email protected]", "firstName"=>"Alex", "lastName"=>"Nadalin", "birthday"=>"21/10/1988", }
  17. CREDITS http://www.panoramio.com/photo/30329016 https://farm3.staticflickr.com/2199/2365883747_3a5c753719_o.jpg http://news.buzzbuzzhome.com/2013/04/top-7-aerial-photos-cities.html https://www.flickr.com/photos/superlekker/5917559189/sizes/l https://www.flickr.com/photos/derekbruff/12336187505/sizes/l https://www.flickr.com/photos/chberge/3803475294/sizes/l https://www.flickr.com/photos/neilsingapore/8057578769 https://www.flickr.com/photos/dionnehartnett/6805481856/sizes/l https://www.flickr.com/photos/thomashawk/186339737

    https://www.flickr.com/photos/cesarastudillo/3981364314/sizes/l https://www.flickr.com/photos/an_untrained_eye/6630719431 https://www.flickr.com/photos/30835738@N03/7936491790/sizes/l https://www.flickr.com/photos/deboni/2959228565/sizes/l https://www.flickr.com/photos/ghalog/6782751111/sizes/l https://www.flickr.com/photos/timzim/177640262/sizes/o/ https://www.flickr.com/photos/innoxiuss/2824204305 https://www.flickr.com/photos/hawk59/6038847752/sizes/l https://www.flickr.com/photos/remydwd/5487417702/sizes/l https://www.flickr.com/photos/rammorrison/4359793666/sizes/o/ https://www.flickr.com/photos/piers_nye/2501994750/sizes/o/ https://www.flickr.com/photos/danielygo/7559750132/sizes/l https://www.flickr.com/photos/msc72/2600035028/sizes/l https://www.flickr.com/photos/sicilianitaliano/3609275241/sizes/l https://www.flickr.com/photos/scottmontreal/7235110028/sizes/l https://www.flickr.com/photos/piet_musterd/6170853224/sizes/l https://www.flickr.com/photos/music_embassy/7137413247/sizes/l http://upload.wikimedia.org/wikipedia/commons/9/9c/William_James_b1842c.jpg http://theverybesttop10.files.wordpress.com/2013/08/the-world_s-top-10-things-no-person-with-a-ocd-should-see-1. jpg https://www.flickr.com/photos/62244271@N03/8553590682/sizes/l