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
URL ANOTOMY
UR I - Uniform Resource
I d e n t i f i e r
UR L - Uniform Resource L o c a t o r
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
HTTP request message is sent from the client (Brower)
to HTTP Web-Server.
Request message contain:
location of a resource or resource URI
HTTP method to use when accessing the resource.
Optional request headers (name-value pairs)
providing additional information
Request body that identifies additional data to be
uploaded to the server (e.g. form parameters,
attachments, etc.)
HTTP REQUEST MESSAGE
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 response
Supplies optional response body that identifies
additional data to be downloaded to the server (e.g. html,
images, attachments etc.
HTTP RESPONSE MESSAGE
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
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
Request/ Response Entity Header
Carry information about the content
Mainly part of HTTP Response
Entity Headers
HTTP HEADER – ENTITY
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
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
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
Uniform Resource Identifier
In a RESTful web service, It is a hyperlink to a resource
Means for clients and servers to exchange representations of
resources
ex.
.../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
Representation of resources is what is sent back and forth between clients
& servers
So, we never send or receive resources, only their representations
REPRESENTATION
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
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
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
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.
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
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
HTTP as Uninform Interface
Restful Approach Traditional Approach
Focus on resource names Focused on the actions to be
performed on resources
Four specific actions that we can take
upon resources — Create, Retrieve,
Update, and Delete (CRUD)
Countless actions with no naming or
implementation standards
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
Student (identified by name):
http://restfuljava.com/students/{name}
List of students:
http://restfuljava.com/students
CLASSROOM EXAMPLE - URIs
CLASSROOM EXAMPLE - REPRESENTATIONS
GET POST PUT DELETE
GET 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
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
Resource URL Mapping with HTTP Method
HTTP
Methods
Resource CRUD OperationsResource URI
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
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.
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
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
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
REST Constraints
2. Stateless Server
Each request contains ALL the information
necessary to understand it
Application (session) state is kept on the client
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