Restful Fundamentals
-
Upload
suresh-madhra -
Category
Education
-
view
56 -
download
0
Transcript of Restful Fundamentals
![Page 1: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/1.jpg)
REST Fundamentals – Applying HTTP Methods
![Page 2: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/2.jpg)
REST
Representational State Transfer
![Page 3: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/3.jpg)
REST
HTTP + Resource-Oriented Architecture
![Page 4: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/4.jpg)
AGENDA - HTTP
HTTP
RESOURCE
STATIC
DYNAMIC
URL
RESOURCE LOCATOR
RESOUCRE IDENTIFER
VERBS
GET
POST
PUT
DELETE
CONTENT TYPE MESSAGE
HTTP REQUEST
HTTP RESPONSE
STATUS CODE
1xx - INFORMATIONAL
2xx - SUCCESSFUL
3xx - REDIRECTION
4xx – CLIENT ERROR
5xx – SERVER ERROR
WWW
HTML
![Page 5: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/5.jpg)
WHAT IS THE WEB?
An information system of interlinked hypertext documents and resources
accessed via the Internet
![Page 6: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/6.jpg)
HYPERTEXT DOCUMENTS
![Page 7: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/7.jpg)
HYPERTEXT MARKUP LANGUAGE
![Page 8: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/8.jpg)
AGENDA - HTTP
HTTP
RESOURCE
STATIC
DYNAMIC
URL
RESOURCE LOCATOR
RESOUCRE IDENTIFER
VERBS
GET
POST
PUT
DELETE
CONTENT TYPE MESSAGE
HTTP REQUEST
HTTP RESPONSE
STATUS CODE
1xx - INFORMATIONAL
2xx - SUCCESSFUL
3xx - REDIRECTION
4xx – CLIENT ERROR
5xx – SERVER ERROR
WWW
HTML
![Page 9: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/9.jpg)
RESOURCES
Anything that can be identified, named, addressed or
handled on the Web
![Page 10: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/10.jpg)
RESOURCE
▫ Can be concrete things :• Web Pages• Video fi les• Artic les• Blogs• Image fi le
![Page 11: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/11.jpg)
RESOURCE
▫ Can be static and dynamic
![Page 12: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/12.jpg)
RESOURCE
▫ Can a lso represent abstract concepts• Employee or Product or Order• Time• Money Transfer• Calendar• User Accounts
![Page 13: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/13.jpg)
AGENDA HTTP
HTTP
RESOURCE
STATIC
DYNAMIC
URL
RESOURCE LOCATOR
RESOUCRE IDENTIFER
VERBS
GET
POST
PUT
DELETE
CONTENT TYPE MESSAGE
HTTP REQUEST
HTTP RESPONSE
STATUS CODE
1xx - INFORMATIONAL
2xx - SUCCESSFUL
3xx - REDIRECTION
4xx – CLIENT ERROR
5xx – SERVER ERROR
WWW
HTML
![Page 14: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/14.jpg)
URL
Uniform Resource Locator
A URL is a specialization of URI that defines the network location of resource
URL defines how the resource can be obtained
eg.http://some.domain.com/orderinfo?id=123
![Page 15: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/15.jpg)
URL ANOTOMY
U R I - Un ifor m Res ou rc e I d e n ti fi e r
U R L - Un ifo r m Res ou rc e L o c a t o r
![Page 16: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/16.jpg)
RESOURCE IDENTFIERS
A resource only exists on the Web if it has an identifier (URI)
![Page 17: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/17.jpg)
RESOURCE NAMES
▫ URN - Uniform Resource Nam e• products/54321 • about-us• artic les/web.html• posts/2015-01-12• podcasts/rest .mp3• products/9595
![Page 18: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/18.jpg)
AGENDA
HTTP
RESOURCE
STATIC
DYNAMIC
URL
RESOURCE LOCATOR
RESOUCRE IDENTIFER
CONTENT TYPE VERBS
GET
POST
PUT
DELETE
MESSAGE
HTTP REQUEST
HTTP RESPONSE
STATUS CODE
1xx - INFORMATIONAL
2xx - SUCCESSFUL
3xx - REDIRECTION
4xx – CLIENT ERROR
5xx – SERVER ERROR
WWW
HTML
![Page 19: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/19.jpg)
HTTP can transfer any kind of information between clients and servers
E.g. Text files, PDF, e-documents, images, videos, etc.
In any case, the data is streamed over TCP/IP and browser knows how to interpret the binary streams because of the HTTP protocol response header Content-Type
CONTENT-TYPES
![Page 20: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/20.jpg)
AGENDA
HTTP
RESOURCE
STATIC
DYNAMIC
URL
RESOURCE LOCATOR
RESOUCRE IDENTIFER
CONTENT TYPE VERBS
GET
POST
PUT
DELETE
MESSAGE
HTTP REQUEST
HTTP RESPONSE
STATUS CODE
1xx - INFORMATIONAL
2xx - SUCCESSFUL
3xx - REDIRECTION
4xx – CLIENT ERROR
5xx – SERVER ERROR
WWW
HTML
![Page 21: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/21.jpg)
HTTP VERBS
![Page 22: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/22.jpg)
AGENDA
HTTP
RESOURCE
STATIC
DYNAMIC
URL
RESOURCE LOCATOR
RESOUCRE IDENTIFER
CONTENT TYPE VERBS
GET
POST
PUT
DELETE
MESSAGE
HTTP REQUEST
HTTP RESPONSE
STATUS CODE
1xx - INFORMATION
2xx - SUCCESSFUL
3xx - REDIRECTION
4xx – CLIENT ERROR
5xx – SERVER ERROR
WWW
HTML
![Page 23: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/23.jpg)
HTTP STATUS CODE
S e r v e r ’s p r o c e s s e d s t a t u s c o r r e s p o n d i n g t o a r e q u e s t C o m b i n a ti o n o f n u m e r i c a l c o d e & s h o r t d e s c r i p ti o n
![Page 24: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/24.jpg)
AGENDA
HTTP
RESOURCE
STATIC
DYNAMIC
URL
RESOURCE LOCATOR
RESOUCRE IDENTIFER
CONTENT TYPE VERBS
GET
POST
PUT
DELETE
MESSAGE
HTTP REQUEST
HTTP RESPONSE
STATUS CODE
1xx - INFORMATIONAL
2xx - SUCCESSFUL
3xx - REDIRECTION
4xx – CLIENT ERROR
5xx – SERVER ERROR
WWW
HTML
![Page 25: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/25.jpg)
HYPERTEXT TRANSFER PROTOCOL
ServerClient
Yahoo.comMozilla Firefox
![Page 26: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/26.jpg)
HTTP COMMUNICATION
![Page 27: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/27.jpg)
HTTP MESSAGE - REQUEST
ServerClient
Yahoo.comMozilla Firefox HTTP Request
GET /HTTP/1.1User-Agent: Mozilla Firefox Host: example.comAccept: */*
![Page 28: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/28.jpg)
HYPERTEXT TRANSFER PROTOCOL
ServerClient
Yahoo.comMozilla Firefox
HTTP Response
HTTP/1.1 200 OKContent-Type: text/html Content-Length: 1270
<!doctype html><html><head>
<title>Example Domain</title>
</head><body> … </body></html>
![Page 29: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/29.jpg)
HTTP request message is sent from the client (Brower) to HTTP Web-Server.
Request message contain:
location of a resource or resource URIHTTP method to use when accessing the resource.Optional request headers (name-value pairs) providing additional informationRequest body that identifies additional data to be uploaded to the server (e.g. form parameters, attachments, etc.)
HTTP REQUEST MESSAGE
![Page 30: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/30.jpg)
HTTP response message is sent from HTTP Web-Server back to the client (Web-Browser).
Response message contain:
Carry status of processed request.Provide response headers (name-value pairs) providing additional information about the responseSupplies optional response body that identifies additional data to be downloaded to the server (e.g. html, images, attachments etc.
HTTP RESPONSE MESSAGE
![Page 31: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/31.jpg)
HTTP MESSAGE FORMAT
![Page 32: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/32.jpg)
Request Line
Response
BOTH
HTTP MESSAGE FORMAT
![Page 33: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/33.jpg)
/fruits/list?category=fruits&limits=20
Path to resource
Query string
HTTP /1.1
HTTP HEADER – REQUEST LINE
![Page 34: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/34.jpg)
Request/ Response General Header
Carry information about the HTTP transaction
Can be a part of request, as well as response
General Headers
HTTP HEADER – GENERAL
![Page 35: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/35.jpg)
Request Header
Specific to an HTTP Request Carry information about the client, and the type of request Facilitates better understanding between client and server
Request Headers
HTTP HEADER – REQUEST
![Page 36: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/36.jpg)
Request/ Response Entity Header
Carry information about the content Mainly part of HTTP Response
Entity Headers
HTTP HEADER – ENTITY
![Page 37: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/37.jpg)
HTTP REQUEST RESPONSE MESSAGE EXCHANGE
![Page 38: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/38.jpg)
REST
Representational State Transfer
![Page 39: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/39.jpg)
REST
HTTP + Resource-Oriented Architecture
![Page 40: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/40.jpg)
REST
HTTP + Resource-Oriented ArchitectureRESTful
![Page 41: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/41.jpg)
What is REST?
REST is not a technology, nor a framework
REST is an architectural style - Set of principles & constraints
Why constraints?
Constraints help us in developing applications that are “easy” to maintain and extend.
REST
![Page 42: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/42.jpg)
MAJOR PLAYERS
![Page 43: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/43.jpg)
REST ACTORS
REST
RESOURCES REPRESENTATION ACTIONS
![Page 44: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/44.jpg)
REST ACTORS
REST
RESOURCES REPRESENTATION ACTIONS
![Page 45: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/45.jpg)
In general, a RESTful resource is anything that is addressable over Web
Addressable = anything that can be accessed and transferred between clients and servers
Resource must have a unique address over the Web
Under HTTP these are URIs
RESOURCES
![Page 46: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/46.jpg)
In a RESTful web service, Resources are categorized as:
Singleton resource is a single chunk of information, similar to a row in a database table.
Collection resource is a set of resources with the same structure, similar to a selection of rows in a database table.
RESOURCES MODEL
![Page 47: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/47.jpg)
Uniform Resource Identifier
In a RESTful web service, It is a hyperlink to a resource Means for clients and servers to exchange
representations of resourcesex.
.../orderinfo?id=123 Only means to locate a specific resource Used to negotiate representations of a given resource
In the url you give certain parameters that define which information you want the server to return to you (just like giving GET variables to a page). Server will respond you with a resource representation containing the information you’ve asked
URIs
![Page 48: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/48.jpg)
URIs are also used to link resources together. ex.
URIs
![Page 49: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/49.jpg)
REST ACTORS
REST
RESOURCES REPRESENTATION ACTIONS
![Page 50: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/50.jpg)
Representation of resources is what is sent back and forth between clients & servers
So, we never send or receive resources, only their representations
REPRESENTATION
![Page 51: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/51.jpg)
Format of the representation is determined by the content-type
Interaction of the representation on the resource is determined by the action (GET, POST etc.)
REPRESENTATION
![Page 52: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/52.jpg)
Different clients are able to consume different representations of the same resource
A representation can take various forms, such as:
• image• a text file• an XML stream• a JSON stream
Note: But its resource has to be available through the same URI
REPRESENTATION FORMATS
![Page 53: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/53.jpg)
REPRESENTATION FORMATS
For human-generated requests through a web browser, a representation is typically in the form of an HTML page
For automated requests from other web services, readability is not as important and a more efficient representation can be used such as XML or JSON
![Page 54: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/54.jpg)
REST ACTORS
REST
RESOURCES REPRESENTATION ACTIONS
![Page 55: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/55.jpg)
ACTIONS
Actions are used to operate on resources
For example, they can be used for– getting info about a movie– adding a photo to Flickr– deleting a file from a folder
Note: Data transmitted to and from the resource is a representation of it.
![Page 56: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/56.jpg)
HTTP-BASED ACTIONS
Note: RESTful web services can also execute logic at the server level, but remembering that every result must be a resource representation
![Page 57: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/57.jpg)
HTTP as Uninform Interface
Note: RESTful web services can also execute logic at the server level, but remembering that every result must be a resource representation
![Page 58: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/58.jpg)
HTTP as Uninform Interface
Restful Approach Traditional ApproachFocus on resource names Focused on the actions to be
performed on resourcesFour specific actions that we can take upon resources — Create, Retrieve, Update, and Delete (CRUD)
Countless actions with no naming or implementation standards
![Page 59: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/59.jpg)
HTTP as Uninform Interface
![Page 60: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/60.jpg)
Artificial example of a web service handling students in some classroom
Location of the service = http://restfuljava.com/ Resources
are represented as XML streams
CLASSROOM EXAMPLE
![Page 61: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/61.jpg)
Student (identified by name):http://restfuljava.com/students/{name}
List of students:http://restfuljava.com/students
CLASSROOM EXAMPLE - URIs
![Page 62: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/62.jpg)
Student Schema
<student><name>Jane</name><age>10</age><link>/students/Jane</link>
</student>
CLASSROOM EXAMPLE - REPRESENTATIONS
![Page 63: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/63.jpg)
Students List:
<students><student>
<name>Jane</name><age>10</age><link>/students/Jane</link>
</student><student>
<name>John</name><age>11</age><link>/students/John</link>
</student></students>
CLASSROOM EXAMPLE - REPRESENTATIONS
![Page 64: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/64.jpg)
CLASSROOM EXAMPLE - REPRESENTATIONS
GET POST PUT DELETEGET is used to RETRIEVE resources
POST is used to CREATE resources
PUT is used to UPDATE resources
DELETE is used to DELETE resources
No side effects Has side effects Has side effects Has side effects
Can also return only parts of the resource
The resource identity/URL is not known at creation time
Return updated resource URL
Used for Read operation and query
![Page 65: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/65.jpg)
GET EXAMPLE
![Page 66: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/66.jpg)
POST EXAMPLE
![Page 67: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/67.jpg)
The initial GET is
omitted here
PUT EXAMPLE
![Page 68: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/68.jpg)
DELETE EXAMPLE
![Page 69: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/69.jpg)
REST Constraints
1. Uniform Interfaces – Resource Model• Every resource has a unique id which uniquely identify.• Every resource has URI [Uniform Resource Identifier].
URI Syntax URI
![Page 70: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/70.jpg)
Resource URL Mapping with HTTP Method
HTTP Methods
Resource CRUD OperationsResource URI
![Page 71: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/71.jpg)
REST Constraints
![Page 72: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/72.jpg)
REST Constraints
Uniform Interface
![Page 73: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/73.jpg)
REST Constraints
1. Uniform Interfaces
![Page 74: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/74.jpg)
REST Constraints
1. Uniform Interfaces - Resources
![Page 75: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/75.jpg)
REST Constraints
1. Uniform Interfaces - Resource• Resource is a chunk of related information of an entity.• Can be static and dynamic.• Resources words are ‘NOUNS’ such as Movies, Employees, Products, Photos
![Page 76: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/76.jpg)
REST Constraints
1. Uniform Interfaces – Resource Model• Singleton resource is a single chunk of information, similar to a row in a database table. • Collection resource is a set of resources with the same structure, similar to a selection of rows in a
database table.
![Page 77: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/77.jpg)
REST Constraints
1. Uniform Interfaces – Resource Model• Every resource has a unique id which uniquely identify.• Every resource has URI [Uniform Resource Identifier].
URI Syntax URI
![Page 78: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/78.jpg)
REST Constraints
1. Uniform Interfaces – Resource Model
Yahoo Social REST APIs
Singleton resource : Following URI defines the profile resource for the user whose ID is 12345.https://social.yahooapis.com/v1/user/12345/profile
The next URI specifies the connections (friends) for the user whose ID is 6677.https://social.yahooapis.com/v1/user/6677/connections
Collection resource : Following URI accesses the collection of schools contained in the profile of the user of ID 98765.https://social.yahooapis.com/v1/user/98765/profile/schools
![Page 79: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/79.jpg)
REST Constraints
1. Uniform Interfaces - Methods
![Page 80: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/80.jpg)
Resource URL Mapping with HTTP Method
HTTP Methods
Resource CRUD OperationsResource URI
REST Constraints
![Page 81: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/81.jpg)
HTTP Methods
![Page 82: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/82.jpg)
REST Constraints
1. Uniform Interfaces - Representations
![Page 83: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/83.jpg)
REST Constraints
Stateless
![Page 84: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/84.jpg)
2. Stateless ServerTwo types of State
Application State Resource State
REST Constraints
![Page 85: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/85.jpg)
2. Stateless Server No client context is stored on the server between requests. Each request from any client contains all of the information
necessary to service the request, and any state is held in the client.
The server can be stateful, this constraint merely requires that server-side state be addressable by URL as a resource.
REST Constraints
![Page 86: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/86.jpg)
REST Constraints
Application StateExchange of Request Identify between Server and Client
![Page 87: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/87.jpg)
REST Constraints
Resource StateWhat is stored on the server (Beyond Session)
![Page 88: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/88.jpg)
REST Constraints
2. Stateless Server Each request contains ALL the information
necessary to understand it
Application (session) state is kept on the client
![Page 89: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/89.jpg)
REST Constraints
2. Stateless Server
Visibility - Performance
Reliability - Consistency
Scalability
![Page 90: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/90.jpg)
REST Constraints
Client Server
![Page 91: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/91.jpg)
1. Client - Server
Separation of Concerns: Client responsible for UI Server responsible for data
storage
REST Constraints
![Page 92: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/92.jpg)
1. Client - Server
REST Constraints
+ Scalability + Simplicity
![Page 93: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/93.jpg)
REST Constraints
Cache
![Page 94: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/94.jpg)
REST Constraints
3. Cache Clients are able to cache responses. Responses must, implicitly or explicitly, define themselves as
cacheable or not.
![Page 95: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/95.jpg)
REST Constraints
3. Cache
Efficiency Scalability UP
Performance
![Page 96: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/96.jpg)
REST Constraints
Layered System
![Page 97: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/97.jpg)
AN EXMAPLE
HTTP server:
example.com
![Page 98: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/98.jpg)
READING A TEXT RESOURCE
http://example.com/hello-world.txt
GET /hello-world.txt HTTP/1.1 Host: example.com
HTTP Request
![Page 99: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/99.jpg)
READING A TEXT RESOURCE
http://example.com/hello-world.txt
HTTP Response
HTTP/1.1 200 OKContent-Type: text/plain Content-Length: 13
Hello, World!
![Page 100: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/100.jpg)
CREATING A TEXT RESOURCE
POST / HTTP/1.1 Host: example.comContent-type: text/plan
Hello Mars
HTTP Request
![Page 101: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/101.jpg)
CREATING A TEXT RESOURCE
HTTP/1.1 201 Created Location: /hello-mars.txt
HTTP Response
![Page 102: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/102.jpg)
RESOURCE DOES NOT EXIST
http://example.com/hello-world.txt
GET /hello-world.txt HTTP/1.1 Host: example.com
HTTP Request
![Page 103: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/103.jpg)
RESOURCE DOES NOT EXIST
HTTP/1.1 404 Not Found
HTTP Response
![Page 104: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/104.jpg)
EMPLOYEE RESOURCE
N a m e G e n d e r R o l e
![Page 105: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/105.jpg)
XML REPRESENTATION
<employee>
<name>Alice</name>
<role>Developer</role>
<gender>female</gender>
</employee>
![Page 106: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/106.jpg)
JSON REPRESENTATION
{
"name": "Alice","role": "Developer", "gender": "female"
}
![Page 107: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/107.jpg)
HTML REPRESENTATION
<h1>Alice</h1>
<dl>
<dt>Role:</dt>
<dd>Developer</dd>
<dt>Gender:</dt>
<dd>Female</dd>
</dl>
![Page 108: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/108.jpg)
EMPLOYEE RESOURCE
/employees/alice
/employees/bob
/employees/eve
![Page 109: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/109.jpg)
RESOURCE OPERATIONS
![Page 110: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/110.jpg)
LIST EMPLOYEE RESOURCES
GET /employees HTTP/1.1 Host: example.com Accept: application/xml
HTTP Request
![Page 111: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/111.jpg)
LIST EMPLOYEE RESOURCES
HTTP Response
HTTP/1.1 200 OKContent-Type: application/xml
<employees><employee href="/employees/alice"/><employee href="/employees/bob"/><employee href="/employees/eve"/>
</employee>
![Page 112: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/112.jpg)
LIST EMPLOYEE RESOURCES
HTTP Response
HTTP/1.1 200 OKContent-Type: application/xml
<employees><employee href="/employees/alice"/><employee href="/employees/bob"/><employee href="/employees/eve"/>
</employee>
![Page 113: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/113.jpg)
READ EMPLOYEE RESOURCE
GET /employees/alice HTTP/1.1 Host: example.com Accept: application/xml
HTTP Request
![Page 114: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/114.jpg)
READ EMPLOYEE RESOURCE
HTTP Response
HTTP/1.1 200 OKContent-Type: application/xml
<employees><name>Alice</name><role>Developer</role><gender>Female</gender>
</employee>
![Page 115: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/115.jpg)
CREATE EMPLOYEE RESOURCE
HTTP Request
POST /employees HTTP/1.1 Host: example.comContent-Type: application/xml
<employee><name>John</name><role>QA</role><gender>male</gender>
</employee>
![Page 116: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/116.jpg)
CREATE EMPLOYEE RESOURCE
HTTP Response
HTTP/1.1 200 OK
![Page 117: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/117.jpg)
UPDATE EMPLOYEE RESOURCE
HTTP Request
PUT /employees/alice HTTP/1.1 Host: example.comContent-Type: application/xml
<employee><name>Alice</name><role>Manager</role><gender>female</gender>
</employee>
![Page 118: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/118.jpg)
UPDATE EMPLOYEE RESOURCE
HTTP Response
HTTP/1.1 201 Created Location: /employees/john
![Page 119: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/119.jpg)
DELETE EMPLOYEE RESOURCE
HTTP Request
DELETE /employees/alice HTTP/1.1 Host: example.comContent-Type: application/xml
![Page 120: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/120.jpg)
DELETE EMPLOYEE RESOURCE
HTTP Response
HTTP/1.1 204 NO Content
![Page 121: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/121.jpg)
RESOURCE ORIENTED ARCHITECTURE
Addressability
Statelessness
C on ne cted n ess
Uniform Interface
![Page 122: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/122.jpg)
ADDRESSSABILITY
Every interesting piece of information the server can provide
should be exposed as a resource, and given its own URI
http://example.com/employees/alice
![Page 123: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/123.jpg)
STATELESSNESS
Every HTTP request should happen in complete isolation
http://google.com/search?q=jellyfish
![Page 124: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/124.jpg)
STATELESSNESS
![Page 125: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/125.jpg)
STATELESSNESS
http://google.com/search?q=jellyfish&start=10
![Page 126: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/126.jpg)
STATELESSNESS
Application State vs. Resource State
![Page 127: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/127.jpg)
CONNECTEDNESS
Documents should contain not just data, but
links to other resources
![Page 128: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/128.jpg)
CONNECTEDNESS
![Page 129: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/129.jpg)
CONNECTEDNESS
![Page 130: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/130.jpg)
CONNECTEDNESS
![Page 131: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/131.jpg)
CONNECTEDNESS
{"employees": [ "/employees/alice",
"/employees/bob", "/employees/eve",
...]
"next_page": "/employees?start=10",
"create_employee": "/employees"
}
![Page 132: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/132.jpg)
HATEOS
Hypermedia As The Engine of Application State
![Page 133: Restful Fundamentals](https://reader036.fdocuments.in/reader036/viewer/2022062523/58a3003f1a28abea508b4aef/html5/thumbnails/133.jpg)
REST Constraints