WEB SERVICES

Cedric Exbrayat


@cedric_exbrayat


ninja squad

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

2 protocoles

SOAP

REST

SOAP

Simple

Object

Access

Protocol

Simple

Complex

Object

RPC

SOAP

CRAP

1998 - Microsoft

HTTP/S et SMTP

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>
					

WSDL

ebay

amazon

SoapFault

DEMO SOAPUI

+++

Generation automatique

Contrat fixe

Outils

---

verbeux

lent

contraignant

REST

Representational State Transfer

2000 - Roy Fielding

Stateless

JSON ou XML


{
  "name": "Cédric Exbrayat",
  "company": "Ninja Squad",
  "email": "cedric@ninja-squad.com",
  "twitter": "cexbrayat",
  "assocs" : ["JUG", "Mixit"]
}
					

Respect du web

URI

http://server.com/users/cexbrayat

HTTP verb

GET - POST - PUT - DELETE

getAllUsers

GET /users

getUserById(id)

GET /users/{id}

createUser

POST /users


{
  "name": "Cédric Exbrayat",
  "company": "Ninja Squad",
  "email": "cedric@ninja-squad.com",
  "twitter": "cexbrayat",
  "assocs" : ["JUG", "Mixit"]
}
					

deleteUser(id)

DELETE /users/{id}

updateUser

PUT /users/{id}

searchUser

Code http

3 cas courants

OK, erreur client, erreur serveur

OK

Bad request

Internal Server Error

Created

Not Modified

Not Found

I'm a teapot

Reponse

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

Demo

github

Pragmatist

vs

RESTafarian

Api sub domain

http://api.github.com

Verbs are bad

Nouns are good

noms concrets

lower case

pluriel

Eviter

/items

/Product

Attributs names

"created_at": Twitter, Github

"createdAt": Foursquare

Versioning

/v1/users

Pagination

/users?limit=120

/users?page=2&count=30

/users?fields=name,email

Pas de ressources?

/shares/goog/convert?from=USD&to=EUR

Authentification

OAuth2

Websocket

Temps réel

Bi directionnel

handshake -> http

communication -> tcp

Firefox6

Chrome14

IE10

Fallback

Demo

Merci

http://github.com/cexbrayat/ws-101