webapp #3 : api
DESCRIPTION
WebApp #3 : APITRANSCRIPT
![Page 1: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/1.jpg)
WebApp : A Beginner's Guide to REST API
![Page 2: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/2.jpg)
0. HTTP
![Page 3: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/3.jpg)
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
![Page 4: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/4.jpg)
Requête HTTP ?
Méthode + UrlGET
POST PUT DELETE
http://www.google.fr
![Page 5: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/5.jpg)
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
![Page 6: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/6.jpg)
Url ?
http://www.thecorneliusclub.com/app/courses/developpeur-web-101
Protocole
Sous-domaine
Nom de domaine
Nom de la ressource
![Page 7: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/7.jpg)
Client HTTP ?
WGETcURL
![Page 8: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/8.jpg)
Serveurs HTTP ?
![Page 9: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/9.jpg)
1. HTTP & WebApp
![Page 10: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/10.jpg)
Application web classique
Utilisateur InternetClient http
Serveur physique
http://thecorneliusclub.com Requête http
Requête http
SQL Document
Données
![Page 11: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/11.jpg)
WebApp & backend (1)
App mobile
Website
Service tiers
Requête http
Backend 1
Backend 2
Backend 3
Requête http
JSON / XML
Requête http
JSON / XML
![Page 12: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/12.jpg)
WebApp & backend (1)
App mobile
Website
Service tiers
Requête http
Backend 1
Backend 2
Backend 3
Requête http
JSON / XML
Requête http
JSON / XML
Impossible à
maintenir !
![Page 13: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/13.jpg)
WebApp & backend (2)
App mobile
Website
Service tiers
Requête http
Backend
Requête http
JSON / XML
Requête http
JSON / XML
![Page 14: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/14.jpg)
WebApp & backend (2)
App mobile
Website
Service tiers
Requête http
Backend
Requête http
JSON / XML
Requête http
JSON / XML
Architecture trop
complexe !
![Page 15: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/15.jpg)
WebApp & backend (3)
App mobile
Website
Service tiers
Requête http
API
Requête http
JSON / XML
Requête http
JSON / XML
JSON / XML
![Page 16: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/16.jpg)
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
![Page 17: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/17.jpg)
2. REST
![Page 18: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/18.jpg)
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
![Page 19: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/19.jpg)
Client–server-
Stateless-
Cacheable-
Layered system-
Uniform interface
Architectural constraints
![Page 20: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/20.jpg)
Uniform interface (1)
Identification of resourcesIndividual resources are identified in requests, for example
using URIs in web-based REST systems.
Manipulation of resourcesWhen a client holds a representation of a resource, including any metadata attached, it has enough information to modify
or delete the resource.
![Page 21: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/21.jpg)
Uniform interface (2)
Self-descriptive messagesEach message includes enough information to describe how to
process the message.
HATEOASA REST client needs no prior knowledge about how to interact
with any particular application or server beyond a generic understanding of hypermedia.
![Page 22: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/22.jpg)
3. Mise en pratique
![Page 23: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/23.jpg)
REST & URLs (1)
/coursCollection d’éléments
![Page 24: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/24.jpg)
REST & URLs (2)
/cours/webdesignElément d’une collection
![Page 25: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/25.jpg)
REST & HTTP methods (1)
POSTGETPUTDELETE
CréerLireModifierSupprimer
![Page 26: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/26.jpg)
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
![Page 27: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/27.jpg)
HATEOAS
/cours/webdesign/chapitresAssociations
![Page 28: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/28.jpg)
Paramètres (1)
/cours?limit=10&offset=50Pagination
![Page 29: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/29.jpg)
Paramètres (2)
/search?q=uxRecherche
![Page 30: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/30.jpg)
4. Tools & Best Practices
![Page 31: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/31.jpg)
Versioning
/v1/cours
![Page 32: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/32.jpg)
Limiter les champs
/cours?fields=id,name
![Page 33: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/33.jpg)
Format
JSON
![Page 34: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/34.jpg)
HTTP codes (1)
200 OKResponse to a successful GET, PUT, PATCH or DELETE.
201 CreatedResponse 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 ContentResponse 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
![Page 35: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/35.jpg)
HTTP codes (2)
400 Bad Request The request is malformed, such as if the body does not parse
401 UnauthorizedWhen no or invalid authentication details are provided. Also useful to trigger an auth
popup if the API is used from a browser
403 ForbiddenWhen authentication succeeded but authenticated user doesn't have access to the
resource
404 Not FoundWhen 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
![Page 36: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/36.jpg)
Error
HTTP Code AND message
![Page 37: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/37.jpg)
Debug
https://chrome.google.com/webstore/detail/advanced-rest-client/
hgmloofddffdnphfgcellkdfbfbjeloo
![Page 38: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/38.jpg)
5. Security
![Page 39: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/39.jpg)
Merci pour votre attention.
![Page 40: WebApp #3 : API](https://reader030.vdocuments.fr/reader030/viewer/2022012405/55983f911a28ab01468b4840/html5/thumbnails/40.jpg)
Bibliographie (1)
Demystifying REST - Jeffrey Way http://code.tutsplus.com/tutorials/demystifying-rest--pre-58000
A Beginner's Guide to HTTP and REST - Ludovico Fischer http://code.tutsplus.com/tutorials/a-beginners-guide-to-http-and-rest--net-16340
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?