Beruflich Dokumente
Kultur Dokumente
Topics :
1. Introduction
2. REST and HTTP
3. Designing Resources URIs
4. RESTful URI types
5. HTTP Methods
6. Idempotence in HTTPS methods
7. REST response
8. HATEOS
9. The Richardson Model
Web services are services which are exposed to the internet for programmatic access.
For example we see various games on Facebook even though they haven’t developed it .They do it
by publishing their services . Others developers then write code to consume these services using
their services
The facebook api requests XMLs or JSON which ease that the developer’s side of coding . There are
many ways to design such APIs . one of the way is using RESTful web services.
https exchange
Protocol means the message format which the client and server will understand. Sometimes this
message format is fixed ie in SOAP (Simple Object Access Protocol) uses SOAP protocol
The best part with REST is it can use XML/JSON/Text to communicate . HTTP request uses
put,get,post,delete.
Service definition :
Which represents typically what the service does is called WSDL is a documentation of what are its
input arguments and structure and all . here REST has no formal definition . We have also have some
specification ie the rule that dictate are to be followed and are considered as right . SOAP also uses
certain rules which if not followed are not considered as SOAP services . However the REST has no
such specification too.
REsprentational State Transfer is actually an architectural styling which has certain guidelines ,
criteria and constraints. However if if you apply this style while developing web services they are
known to be REST ful web services
Resource Locations
The website as very similar to APIs which has response using html or css decorated for
representational format in a readable format. But the APIs have simple data with any format. So
here the locations have uri(Uniform Resource Identifier) are similar to urls which looks ups for
something which already exists.
HTTP methods
http also has metadata which says more about the it . For example the status code to understand
what has happen to request and will be processed accordingly
1XX - Informational
2XX – Success
3XX – Redirection
5XX – server error while sending the response it means the response is gthere but there’s some
error while getting it back
202 – success
401 – unauthorized
403 – forbidden
It builds the data as per the format understood by the system . It can be xml / json/text format
Idempotence - put is used when you want to update a resources where as POST is used when to
create a resource
However if you do get method multiple times it wont affect the server and not worry about the side
effects ie it repeatable operation . But delete and put too is repeatable operation and hence called
idempotent methods .But the post method is not repeatable which might lead to duplicacy of the
resources and hence called non-idempotent methods
HATEOAS
H - hypermedia
A - as
T - the
E - engine
O – of
A - application
S – state
It has no service definition . This is because of http ie hyper links to navigate from resource to
resource. Which means the links are the driver that the whole resources are chained to each other.
Leonard Richardson defined this model into 3 different levels . Every REST API belongs to one of
these three models
Level 3 – use of HATEOAS here the response have links tjhat the clients can use , use of collection
uris etc .
1> Instance uri here each uri has unique id to represent the a resource for the instance
2> Collection uris what if you want to all the resources for instance if you are buidling a website
similar to fcebook then you’ll have resources uris like
Profiles, messages,comments, likes, shares
These uris will be arranged as follows
/profiles/{profileName}
/messages/{messageId}
/messages/{messageId}/comments/{commentId}
/messages/{messageId}/likes/{likeid}
/messages/{messageId}/shares/{shareId}
Level 2 – uses different http methods to do different operations,use of status code etc