Cedric Exbrayat
@cedric_exbrayat
A quoi sert un
Web service?
Echange de données
entre deux applications
par réseau
Echange de données
entre deux devices
par réseau
Simple
Object
Access
Protocol
Format du message
<envelope>
<headers></headers>
<body></body>
</envelope>
XML
repandu en entreprise et open source
simple a lire
Requête
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
</soap:Header>
<soap:Body>
<m:GetStockPrice xmlns:m="http://www.example.org/stock">
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
Réponse
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
+++
Generation automatique
Contrat fixe
Outils
---
verbeux
lent
contraignant
Representational State Transfer
{
"name": "Cédric Exbrayat",
"company": "Ninja Squad",
"email": "cedric@ninja-squad.com",
"twitter": "cexbrayat",
"assocs" : ["JUG", "Mixit"]
}
URI
http://server.com/users/cexbrayat
GET - POST - PUT - DELETE
POST /users
{
"name": "Cédric Exbrayat",
"company": "Ninja Squad",
"email": "cedric@ninja-squad.com",
"twitter": "cexbrayat",
"assocs" : ["JUG", "Mixit"]
}
Code http
3 cas courants
OK, erreur client, erreur serveur
HTTP status 403
{
"code": "14",
"developerMessage": "this user has not enough credentials to access admin repository",
"more": "http://mywebsite.com/api/errors/14",
"userMessage": "You can't access this repository",
}
Content type negociation
application/json
application/xml
HATEOAS
Hypermedia as the Engine
of Application State
Pragmatist
vs
RESTafarian
Api sub domain
http://api.github.com
Verbs are bad
Nouns are good
noms concrets
lower case
pluriel
Attributs names
"created_at": Twitter, Github
"createdAt": Foursquare
Pagination
/users?limit=120
/users?page=2&count=30
/users?fields=name,email
Pas de ressources?
/shares/goog/convert?from=USD&to=EUR
handshake -> http
communication -> tcp
Merci
http://github.com/cexbrayat/ws-101