10. HTTP Status Codes
●
200 OK
●
201 Created
●
400 Bad Request
●
401 Unauthorized
●
404 Not Found
●
500 Internal Server Error
11. يعني ايه رست ؟
Representational State Transfer
A client has a state ( set of variables' values)
The client initiates a request to a resource URI
The 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 each
resource representation → Representational State Transfer!
12. REST
● Software Architecture Style
● Introduced by Roy Fielding
● Based on HTTP
13. 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
14. REST Request consists of ...
●
Resources
●
nouns
●
Identified by a URI
●
Methods
●
verbs
●
GET, POST, PUT, and DELETE
●
Sate Representation
●
Session, parameters
16. 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
17. 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
18. Login
● URI: http://api.blog.com/session
● Method: POST
● Parameters: user-name, password
● Return
● 201 – Created
● 400 – Bad request
20. Write a Post
● URI: http://api.blog.com/posts
● Method: POST
● Parameters: title, body
● Return
● 201 – Created
● 400 – Bad request
21. Write/Edit a Post
● URI: http://api.blog.com/posts/hello-world
● Method: PUT
● Parameters: title, body
● Return
● 201 – Created
● 400 – Bad request
22. Delete a Post
● URI: http://api.blog.com/posts/hello-world
● Method: DELETE
● Parameters: N/A
● Return
● 200 – OK
● 401 – Not authorized
23. Read a Post
● URI: http://api.blog.com/posts/hello-world
● Method: GET
● Parameters: N/A
● Return
● 200 – OK
● 404 – Not found
24. Comment on post
● URI: http://api.blog.com/posts/hello-
world/comments
● Method: POST
● Parameters: comment
● Return
● 201 – Created
● 400 – Bad request
25. Edit a Comment
● URI: http://api.blog.com/posts/hello-
world/comments/123
● Method: PUT
● Parameters: comment
● Return
● 201 – Created
● 400 – Bad request
26. Delete a comment
● URI: http://api.blog.com/posts/hello-
world/comments/123
● Method: DELETE
● Parameters: N/A
● Return
● 200 – OK
● 401 – Not authorized
27. Like a post
● URI: http://api.blog.com/posts/hello-
world/likes
● Method: POST
● Parameters: N/A
● Return
● 201 – Created
28. Like a comment
● URI: http://api.blog.com/posts/hello-
world/comments/123/likes
● Method: POST
● Parameters: N/A
● Return
● 201 – Created
29. 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
30. JSON
●
JavaScript Object Notation
●
representing simple data structures and
associative arrays, called objects.