Motive : A flashlight on how to architect a web service in a Resource oriented perspective, which is entirely different from the traditional RPC style.
1)Resource : Every interesting thing your application manages should be exposed as a resource.A resource can be anything a client might want to access: a work of art,a piece of information,a physical object,a concept,or a grouping of references to other resources.Resources are Nouns.When you model your requirements,make sure that you consider this fact.
a)A road map of Ladak
b)Some information about India
c)Directory of phone numbers
d)Result of an algorithm
e)Sales number of Q2017
f)The relationship between two people,Alice and Bob
g)List of open bugs in the bug database
Types of resources:
These are the top level directories which include other resources.You can GET these resources but cannot DELETE or modify directly.It’s a predefined resource that acts as a directory of child resources.A website’s homepage is a one-of-a-kind resource.at a well known URI which acts as portal to other resources.
a)An Amazon S3 bucket b)Directory of Users c)A website’s homepage
The resources that are actually exposed for GET,PUT and DELETE.
a)Every S3 object you create is exposed as resource.
3)Resource representing results of an Algorithm
This include collection of resources,which are usually the results of queries.
a)A search engine exposes an infinite number of algorithmic resources.
2)URI : A URI is the name of a resource.A resource may have different names but every resource must have at least one URI. Naming of URI is the most trickiest part.
Below are some guidelines:
1)It must be descriptive and meaningful.
1.1)Use path variables to express the hierarchy.
1.2)Put punctuation characters in path variables to clear confusion where there is no hierarchy.
Example:/Coordinate/x;y or /Coordinate/x,y
1.3)Use query parameters or variables to express inputs into an algorithm.
2)One URI may represent a group of resources.
3)Scoping information about a resource should be understood by looking at a URI.
Examples of RESTFUL URIs:
Examples of RPC URIs:
3)Representation : The representation conveys the state of the resource.A resource representation is what a client receives when it sends a GET request to its URI. A resource’s representation may contain link to other resources(connectedness).The best practice is to have different URIs for different representation of a resource,but the client can ask the server for some particular representation through the Uniform interface.The server takes the decision whether to serve the kind of representation the client is asking or not.
In ROA,we have to design
a) the representations to be served to the client
b) the representation or representations accepted by the client.
We call it as Data Contract between client and server.
4)Query parameters in URI : A path variable in a URI usually represent a Directory or scope structure.But if you want to initiate an algorithm at service side by passing some parameter from client,then use query variables.
5)Dataset : One of the main aspect of Resource Oriented Architecture is to figure out the data set.A web service exposes the different representation of the data set through URIs to the clients.
Examples: For google map service,Data set would be Maps.