rest 101: an overview to representational state transfer

23
REST 101 An Overview to Representational State Transfer API

Upload: omar-fernando-zafe

Post on 13-Apr-2017

55 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: REST 101: An Overview To Representational State Transfer

REST 101

An Overview to Representational State Transfer API

Page 2: REST 101: An Overview To Representational State Transfer

Fernando Zafe

Systems Engineer StudentUniversidad Tecnológica NacionalTucumán, Argentina

🌎 ZAFE.COM.AR 🐙 GITHUB.COM/zafe

Page 3: REST 101: An Overview To Representational State Transfer

What is a Web Service?

• A Web Service is a service offered by an electronic device to another electronic device, communicating with each other via World Wide Web. Source: Wikipedia

Page 4: REST 101: An Overview To Representational State Transfer

What is an API

• API stands for Application Programming Interface

• Is a contract provided by a piece of software to another

• Examples: C++ API, YouTube API,

Page 5: REST 101: An Overview To Representational State Transfer

What is REST

• REST stands for REpresentational State Transfer

• It’s a software architectural style

• Proposed by Roy Fielding in 2000

Page 6: REST 101: An Overview To Representational State Transfer

HTTP

• Stands for Hyper Text Transfer Protocol

• Application layer protocol used by the World Wide Web

• Used by web browsers and web servers to communicate

Page 7: REST 101: An Overview To Representational State Transfer

HTTP Verbs

• HEAD: This method asks for a response identical to that of a GET request, but without the response body.

• GET: Used for requesting data. It doesn’t modify data from the server

• POST: Used for changing a state on the server. Something has change after this operation. Usually initiated by a web form

Page 8: REST 101: An Overview To Representational State Transfer

HTTP Verbs

• PATCH: requests that the enclosed entity be stored under the supplied URI. If the URI refers to an already existing resource, it is modified; if the URI does not point to an existing resource, then the server can create the resource with that URI

• DELETE: Deletes the specified resource

Page 9: REST 101: An Overview To Representational State Transfer

Constraints

• Client-Server

• Stateless

• Cache

• Interface / Uniform Contract

• Layered System

Page 10: REST 101: An Overview To Representational State Transfer

HATEOAS

Page 11: REST 101: An Overview To Representational State Transfer

HTTP Status Code

Page 12: REST 101: An Overview To Representational State Transfer
Page 13: REST 101: An Overview To Representational State Transfer

2xx

• 200 OK Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.[7]

• 201 Created The request has been fulfilled, resulting in the creation of a new resource.[8]

• 202 Accepted The request has been accepted for processing, but the processing has not been completed. The request might or might not be eventually acted upon, and may be disallowed when processing occurs

• 204 No Content The server successfully processed the request and is not returning any content.[12]

Page 14: REST 101: An Overview To Representational State Transfer

3xx

• 301 Moved Permanently This and all future requests should be directed to the given URI.

• 304 Not Modified Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match. In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy.

Page 15: REST 101: An Overview To Representational State Transfer

4xx

• 400 Bad Request The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).

• 401 Unauthorized Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication. 401 semantically means "unauthenticated", i.e. the user does not have the necessary credentials.

• 403 Forbidden The request was a valid request, but the server is refusing to respond to it. The user might be logged in but does not have the necessary permissions for the resource.

• 404 Not Found The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible

Page 16: REST 101: An Overview To Representational State Transfer

5xx

• 500 Internal Server Error A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

• 501 Not Implemented The server either does not recognize the request method, or it lacks the ability to fulfill the request. Usually this implies future availability (e.g., a new feature of a web-service API)

Page 17: REST 101: An Overview To Representational State Transfer

The Richardson Maturity Model (RMM)

Page 18: REST 101: An Overview To Representational State Transfer

Level 0

Page 19: REST 101: An Overview To Representational State Transfer

Level 1

Page 20: REST 101: An Overview To Representational State Transfer

Level 2

Page 21: REST 101: An Overview To Representational State Transfer

Level 3

Page 22: REST 101: An Overview To Representational State Transfer

Example

Page 23: REST 101: An Overview To Representational State Transfer

Thank you!