PHP Indonesia 3rd meetup - 06/04/13

517 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

PHP Indonesia 3rd meetup - 06/04/13

  1. 1. ReST (Introduction) 3rd Meetup PHP Indonesia 6 April 2013 Surabaya by Glend Maatita
  2. 2. ReST example (Twitter)
  3. 3. ReST example (Facebook)
  4. 4. ReST - History● Representational State Transfer● ReST was re-DISCOVER-ed by Roy Fielding● Doesnt require any external library● Tightly bond with HTTP
  5. 5. ReST – HTTPClient Send Request Server Send ResponseGET / HTTP/1.1Host: xkcd.com HTTP/1.1 200 OKAccept: text/html Date: Sat, 02 Apr 2011 21:05:05 GMTUser-Agent: Mozilla/5.0 Server: lighttpd/1.4.19(Macintosh) Content-Type: text/html <html>...</html>
  6. 6. ReST - HTTP HTTP Verb● GET● POST● PUT● DELETE Routes● URL + HTTP Verb
  7. 7. ReST - Definition“The Same Thing with a different STATEchanges its meaning”“The message is changed based on itsState”
  8. 8. ReST – How To● Loved by developer● Easy to read, easy to understand, easy to learn
  9. 9. ReSTBad !! Imagine :)/getAllUsers /getMentions/getUserById /getUserTimeLine/getUsers /getHomeTimeLine/deleteUser /getStatusesRetweet/updateUser /updateStatuses/deleteUserTenYearsOld /destroyStatus/newUser /getRetweets/getUserUnderTenYearsOld
  10. 10. ReST - Quotes“Web its not about HTML pages, its about resources, and those resources are located by URLs”
  11. 11. So ?● We only need two base URLs as the location of a resource(collection of resource, and single resource)● Resources is Noun, use Noun :)● Plural is better Resource POST GET (READ) PUT DELETE (CREATE) (UPDATE) /users Create new List all Users Update All Delete All user Users Users /users/1 - Show User Update User Delete User (with ID = 1) with ID = 1 (if with ID = 1 Exist)
  12. 12. Association ?Easy :)GET /departments/1/usersPOST /departments/1/usersPUT /users/123DELETE /users/123
  13. 13. QueryUse ? for QueryGET /users?limit=50&offset=100GET /users?username=indra&birth=1990GET /users?column=id,name,username,birthGET /users.json (/users.xml)
  14. 14. Versioning/v1/users/
  15. 15. Terima Kasih Glend Maatita @glend_maatita YM : the_entung glend.maatita@kampus.co.id

×