HTTP Status Codes ● 200 OK ● 201 Created ● 400 Bad Request ● 401 Unauthorized ● 404 Not Found ● 500 Internal Server Error
يعني ايه رست ؟ 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!
REST● Software Architecture Style● Introduced by Roy Fielding● Based on HTTP
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
REST Request consists of ... ● Resources ● nouns ● Identified by a URI ● Methods ● verbs ● GET, POST, PUT, and DELETE ● Sate Representation ● Session, parameters
Example: Blog SystemLets Design our Blogs API!
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
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
Login● URI: http://api.blog.com/session● Method: POST● Parameters: user-name, password● Return ● 201 – Created ● 400 – Bad request