Power of REST - قوة الرست

968 views

Published on

محاضرة قوة الرست من المهندس تامر عبد الراضي

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
968
On SlideShare
0
From Embeds
0
Number of Embeds
176
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Power of REST - قوة الرست

  1. 1. ‫ُ ةِّ سِ ّتْ ّ‬ ‫قور ة رست‬ ‫‪Power of REST‬‬‫إعداد: م/ تامر محمد عبد الراضي‬
  2. 2. ‫مقدمة عن‬‫‪HTTP‬‬
  3. 3. HTTP● Hyper-Text Transfer Protocol● Client-Server networking protocol● Text based → Interoperability● URL Examples: ● www.example.com/pages/first.htm ● www.blog.com/posts/hello-world
  4. 4. HTTP Methods ● HEAD ● GET ● POST ● PUT ● DELETE ● TRACE ● OPTIONS ● CONNECT ● PATCH
  5. 5. GET● used retrieve information● Doesnt have a side effect on the server side = No writes● Cacheable
  6. 6. POST● Add new information● Append entry in a collection/table
  7. 7. PUT● Update existing information● Create new information with a known id
  8. 8. DELETE● Remove an entity
  9. 9. HTTP Status Codes ● 200 OK ● 201 Created ● 400 Bad Request ● 401 Unauthorized ● 404 Not Found ● 500 Internal Server Error
  10. 10. ‫يعني ايه رست ؟‬ Representational State TransferA client has a state ( set of variables values)The client initiates a request to a resource URIThe server response with a representation of the resource.The representation places the client application in a new state.Thus, the client application changes (transfers) state with eachresource representation → Representational State Transfer!
  11. 11. REST● Software Architecture Style● Introduced by Roy Fielding● Based on HTTP
  12. 12. Characteristics of REST● Stateless ● Each request from any client contains all of the information necessary to understand the request ● uniform interface ● GET, POST, PUT, and DELETE ● URIs ● resources that are uniquely identified by URIs ● → http://example.com/orders/101230/customer
  13. 13. REST Request consists of ... ● Resources ● nouns ● Identified by a URI ● Methods ● verbs ● GET, POST, PUT, and DELETE ● Sate Representation ● Session, parameters
  14. 14. Example: Blog SystemLets Design our Blogs API!
  15. 15. Functions of Our Blog ● Login ● Logout ● Write a Post ● Delete a Post ● Edit a Post ● Read a Post ● Comment on a Post ● Delete Comment ● Edit a comment ● Like a post ● Like a comment
  16. 16. Analyze, extract entities● Login = Create a session ● Entities (Nouns) Logout = Delete the session Session● ●● Write a Post ● Post● Delete a Post – Likes● Edit a Post – Comment● Read a Post ● Likes● Comment on a Post● Delete Comment● Edit a comment● Like a post = Add a like to post● Like a comment = Add a like to comment
  17. 17. Login● URI: http://api.blog.com/session● Method: POST● Parameters: user-name, password● Return ● 201 – Created ● 400 – Bad request
  18. 18. Logout● URI: http://api.blog.com/session● Method: DELETE● Parameters: N/A● Return ● 200 – OK
  19. 19. Write a Post● URI: http://api.blog.com/posts● Method: POST● Parameters: title, body● Return ● 201 – Created ● 400 – Bad request
  20. 20. Write/Edit a Post● URI: http://api.blog.com/posts/hello-world● Method: PUT● Parameters: title, body● Return ● 201 – Created ● 400 – Bad request
  21. 21. Delete a Post● URI: http://api.blog.com/posts/hello-world● Method: DELETE● Parameters: N/A● Return ● 200 – OK ● 401 – Not authorized
  22. 22. Read a Post● URI: http://api.blog.com/posts/hello-world● Method: GET● Parameters: N/A● Return ● 200 – OK ● 404 – Not found
  23. 23. Comment on post● URI: http://api.blog.com/posts/hello- world/comments● Method: POST● Parameters: comment● Return ● 201 – Created ● 400 – Bad request
  24. 24. Edit a Comment● URI: http://api.blog.com/posts/hello- world/comments/123● Method: PUT● Parameters: comment● Return ● 201 – Created ● 400 – Bad request
  25. 25. Delete a comment● URI: http://api.blog.com/posts/hello- world/comments/123● Method: DELETE● Parameters: N/A● Return ● 200 – OK ● 401 – Not authorized
  26. 26. Like a post● URI: http://api.blog.com/posts/hello- world/likes● Method: POST● Parameters: N/A● Return ● 201 – Created
  27. 27. Like a comment● URI: http://api.blog.com/posts/hello- world/comments/123/likes● Method: POST● Parameters: N/A● Return ● 201 – Created
  28. 28. Data representation● REST supports variety of formats ● XML ● JSON ● X(HTML)REST supports content negotiation● ● Header-based: GET /foo Accept: application/json ● URL-Based http://api.blog.com/posts/hello-world.json
  29. 29. JSON● JavaScript Object Notation● representing simple data structures and associative arrays, called objects.
  30. 30. { Post : { title : hello-world, body: bla bla bla …, comments : { Comment : [ {name:Folaan, comment:Hi}, {name:3ellan, comment:Hello} ] }, likes: [Follan, 3ellan] }}
  31. 31. ?Questions

×