rest that won't make you cry

Post on 04-Dec-2014

125 Views

Category:

Software

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

by Roman Melnyk, Web developer, SoftServe

TRANSCRIPT

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

Topics to coverClient-server data interchangeRESTLingual principlesHTTP

feat. pictures, marginal jokes, guns and explicit lexicon

Data handling

Lingual principles

Yo serva, gimme sum userz, bro!

Lingual principles

GET 127.0.0.1 /api/users

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←

Outgoing dataPOST and PUT require data:

• Content-Type:

◦application/json

◦application/xml

◦multipart/form-data

◦text/plain

◦text/html

◦text/xml

Incoming dataResponse code:

• 2xx

• 4xx

◦400 Bad Request, 405 Method not allowed

◦401 GTFO Unauthorized

◦403 Forbidden

• 5xx

Incoming dataHeaders:

• Access-Control-Allow-Origin

• Cache-Control, Expires, Pragma

• Content-Encoding

• Content-Language

• Content-Length

• Set-Cookie

Incoming data

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

Incoming data

@GET

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

@Produces("application/json")

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

) throws ApiException;

“Always code

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

— Martin Golding

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

top related