19
REST that won't make you cry Roman Melnyk, Web developer, SoftServe 2014

REST that won't make you cry

Embed Size (px)

DESCRIPTION

by Roman Melnyk, Web developer, SoftServe

Citation preview

Page 1: REST that won't make you cry

REST that won't make you cryRoman Melnyk,Web developer,SoftServe2014

Page 2: REST that won't make you cry

Topics to coverClient-server data interchangeRESTLingual principlesHTTP

feat. pictures, marginal jokes, guns and explicit lexicon

Page 3: REST that won't make you cry
Page 4: REST that won't make you cry

Data handling

Page 5: REST that won't make you cry
Page 6: REST that won't make you cry
Page 7: REST that won't make you cry

Lingual principles

Yo serva, gimme sum userz, bro!

Page 8: REST that won't make you cry

Lingual principles

GET 127.0.0.1 /api/users

Page 9: REST that won't make you cry
Page 10: REST that won't make you cry
Page 11: REST that won't make you cry

Outgoing dataGET /api/users

• GET /api/users/12

• GET /api/users ?loginMask=rmel&createdAfter=2012-12-12

POST /api/users

• POST /api/users/12

PUT /api/users/12

• PUT /api/users sure to do this?←

DELETE /api/users/12

• DELETE /api/users DONT EVEN TRY!!!1111←

Page 12: REST that won't make you cry

Outgoing dataPOST and PUT require data:

• Content-Type:

◦application/json

◦application/xml

◦multipart/form-data

◦text/plain

◦text/html

◦text/xml

Page 13: REST that won't make you cry

Incoming dataResponse code:

• 2xx

• 4xx

◦400 Bad Request, 405 Method not allowed

◦401 GTFO Unauthorized

◦403 Forbidden

• 5xx

Page 14: REST that won't make you cry

Incoming dataHeaders:

• Access-Control-Allow-Origin

• Cache-Control, Expires, Pragma

• Content-Encoding

• Content-Language

• Content-Length

• Set-Cookie

Page 15: REST that won't make you cry
Page 16: REST that won't make you cry

Incoming data

Content-Type must respect MIME typesfor both text and binary content

Page 17: REST that won't make you cry

Incoming data

@GET

@Path("api/users/{id}")

@Produces("application/json")

public User getUserInfo(@PathParam("id") String uid,@QueryParam("filter") String filter

) throws ApiException;

Page 18: REST that won't make you cry

“Always code

as If the guy who ends upmaintaining your codewill be a violent psychopathwho knows where you live.

— Martin Golding

Page 19: REST that won't make you cry

Spend some timehttp://www.restapitutorial.com/

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml