Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

WebApp #3 : API

10,729 views

Published on

WebApp #3 : API

Published in: Software
  • Be the first to comment

  • Be the first to like this

WebApp #3 : API

  1. 1. WebApp : A Beginner's Guide to REST API
  2. 2. 0. HTTP
  3. 3. HTTP ? L'HyperText Transfer Protocol, plus connu sous l'abréviation HTTP est un protocole de communication client-serveur développé pour le World Wide Web. Source : wikipedia.org
  4. 4. Requête HTTP ? Méthode + Url GET POST PUT DELETE http://www.google.fr
  5. 5. Url ? Le sigle URL (Uniform Resource Locator) désigne une chaîne de caractères utilisée pour adresser les ressources du World Wide Web : document HTML, image, sons .… Source : wikipedia.org
  6. 6. Url ? Sous-domaine http://www.thecorneliusclub.com/app/courses/developpeur-web-101 Protocole Nom de domaine Nom de la ressource
  7. 7. Client HTTP ? cURL WGET
  8. 8. Serveurs HTTP ?
  9. 9. 1. HTTP & WebApp
  10. 10. Application web classique http://thecorneliusclub.com Requête http Utilisateur Client http Internet Serveur physique Requête http SQL Document Données
  11. 11. WebApp & backend (1) Website App mobile Service tiers Requête http Backend 1 Backend 2 Backend 3 Requête http JSON / XML Requête http JSON / XML
  12. 12. WebApp & backend (1) Website App mobile Service tiers Requête http Backend 1 Backend 2 Backend 3 Impossible à maintenir ! Requête http JSON / XML Requête http JSON / XML
  13. 13. WebApp & backend (2) Website App mobile Service tiers Requête http Backend Requête http JSON / XML Requête http JSON / XML
  14. 14. WebApp & backend (2) Website App mobile Service tiers Requête http Backend Architecture trop Requête http complexe ! JSON / XML Requête http JSON / XML
  15. 15. WebApp & backend (3) Website App mobile Service tiers Requête http API JSON / XML Requête http JSON / XML Requête http JSON / XML
  16. 16. API ? An API, or Application Programming Interface, at its most fundamental level, is how software applications to talk to each other using the Internet. An API allows you to open up data and other digital resources, to public developers, businesses, or even between departments and locations within a company. Source : http://apievangelist.com
  17. 17. 2. REST
  18. 18. REST ? Representational state transfer (REST) is an abstraction of the architecture of the World Wide Web; more precisely, REST is an architectural style consisting of a coordinated set of architectural constraints applied to components, connectors, and data elements, within a distributed hypermedia system. REST ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements. Source : http://en.wikipedia.org
  19. 19. Architectural constraints Client–server - Stateless - Cacheable - Layered system - Uniform interface
  20. 20. Uniform interface (1) Identification of resources Individual resources are identified in requests, for example using URIs in web-based REST systems. Manipulation of resources When a client holds a representation of a resource, including any metadata attached, it has enough information to modify or delete the resource.
  21. 21. Uniform interface (2) Self-descriptive messages Each message includes enough information to describe how to process the message. HATEOAS A REST client needs no prior knowledge about how to interact with any particular application or server beyond a generic understanding of hypermedia.
  22. 22. 3. Mise en pratique
  23. 23. REST & URLs (1) /cours Collection d’éléments
  24. 24. REST & URLs (2) /cours/webdesign Elément d’une collection
  25. 25. REST & HTTP methods (1) POST GET PUT DELETE Créer Lire Modifier Supprimer
  26. 26. REST & HTTP methods (2) Ressource POST GET PUT DELETE /cours Créer un nouveau cours Liste de tous les cours Modifier tous les cours Supprimer tous les cours /cours/ webdesign ERROR Afficher le cours webdesign Modifier le cours webdesign Supprimer le cours webdesign
  27. 27. HATEOAS /cours/webdesign/chapitres Associations
  28. 28. Paramètres (1) /cours?limit=10&offset=50 Pagination
  29. 29. Paramètres (2) /search?q=ux Recherche
  30. 30. 4. Tools & Best Practices
  31. 31. Versioning /v1/cours
  32. 32. Limiter les champs /cours?fields=id,name
  33. 33. Format JSON
  34. 34. HTTP codes (1) 200 OK Response to a successful GET, PUT, PATCH or DELETE. 201 Created Response to a POST that results in a creation. Should be combined with a Location header pointing to the location of the new resource 204 No Content Response to a successful request that won't be returning a body (like a DELETE request) Source : http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api
  35. 35. HTTP codes (2) 400 Bad Request The request is malformed, such as if the body does not parse 401 Unauthorized When no or invalid authentication details are provided. Also useful to trigger an auth popup if the API is used from a browser 403 Forbidden When authentication succeeded but authenticated user doesn't have access to the resource 404 Not Found When a non-existent resource is requested 405 Method Not Allowed When an HTTP method is being requested that isn't allowed for the authenticated user Source : http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api
  36. 36. Error HTTP Code AND message
  37. 37. Debug https://chrome.google.com/webstore/ detail/advanced-rest-client/ hgmloofddffdnphfgcellkdfbfbjeloo
  38. 38. 5. Security
  39. 39. Merci pour votre attention.
  40. 40. Bibliographie (1) A Beginner's Guide to HTTP and REST - Ludovico Fischer http://code.tutsplus.com/tutorials/a-beginners-guide-to-http-and-rest--net-16340 Demystifying REST - Jeffrey Way http://code.tutsplus.com/tutorials/demystifying-rest--pre-58000 RESTful API Design: Teach a Dog to REST - Brian Mulloy https://blog.apigee.com/detail/restful_api_design Best Practices for Designing a Pragmatic RESTful API - Vinay Sahni http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api RESTful Web APIs - Sam Ruby, Michael Amundsen & Leonard Richardson http://www.amazon.fr/RESTful-Web-APIs-Leonard-Richardson-ebook/dp/B00F5BS966/ref=sr_1_5?

×