REST API - REST Architectural Constraints

REST stands for Representational State Transfer, a term coined by Roy Fielding in 2000. It is an architecture style for designing loosely coupled applications over HTTP, that is often used in the development of web services. REST does not enforce any rule regarding how it should be implemented at a lower level, it just put high-level design guidelines and leave you to think of your own implementation.

 
REST Architectural Constraints are design rules that are applied to establish the distinct characteristics of the REST architectural style.

If you follow all constraints designed by the REST architectural style your system is considered RESTful. 

REST Architectural Constraints

REST defines 6 architectural constraints that make any web service – a true RESTful API.
  • Client-Server
  • Stateless
  • Cacheable
  • Uniform Interface
  • Layered System
  • Code On Demand (Optional) 

Client-Server

This constraint keeps the client and server loosely coupled. In this case, the client does not need to know the implementation details in the server, and the server is not worried about how the data is used by the client. However, a common interface is maintained between the client and server to ease communication. This constraint is based on the principle of Separation of concerns.
Figure: Client-Server
Applying separation of concerns: 
  • Separates user interface concerns from data storage concerns.
  • Improves portability of interface across multiple platforms.
  • Improves scalability by simplifying server components.
  • Allows the components to evolve independently.

Stateless

There should be no need for the service to keep user sessions. In other words, the constraint says that the server should not remember the state of the application. As a consequence, the client should send all information necessary for execution along with each request, because the server cannot reuse information from previous requests as it didn’t memorize them. All info needed is in the message.
 Figure: Stateless
By applying statelessness constraint:
  • Session state is kept entirely on the client.
  • Visibility is improved since a monitoring system does not have to look beyond a single request.
  • Reliability is improved due to easier recoverability from partial failures.
  • Scalability is improved due to not having to allocate resources for storing state
  • The server does not have to manage resource usage across requests. 

Cacheable

This constraint has to support a caching system. The network infrastructure should support a cache at different levels. Caching can avoid repeated round trips between the client and the server for retrieving the same resource.
 Figure: Cacheable
By adding optional non-shared caching:
  • Data within a response to a request is implicitly or explicitly labeled as cacheable or non-cacheable.
  • If a response is cacheable, then a client cache is given the right to reuse that response data for later, equivalent requests.
  • Improves efficiency, scalability, and user-perceived performance.
  • Tradeoff: cacheable constraint reduces Reliability.

Uniform Interface

This constraint indicates a generic interface to manage all the interactions between the client and server in a unified way, which simplifies and decouples the architecture. This constraint indicates that each resource exposed for use by the client must have a unique address and should be accessible through a generic interface. The client can act on the resources by using a generic set of methods.
Figure: Uniform Interface
By applying uniform interface constraint:
The overall system architecture is simplified and the visibility of interactions is improved. Implementations are decoupled from the services they provide and encourage independent evolvability. 

Trade-off: Degrades efficiency since information is transferred in a standardized form rather than one which is specific to the application's needs. Further, a uniform interface has four sub-constraints
  • Identification of resources
  • Manipulation of resources through representations
  • Self-descriptive messages
  • Hypermedia as the engine of application state (HATEOAS)

Identification of resources

Each resource must have a specific and cohesive URI to be made available. REST APIs are designed around resources, which are any kind of object, data, or service that can be accessed by the client.
A resource has an identifier, which is a URI that uniquely identifies that resource. 
For example, the URI for a particular customer order might be:
http://adventure-works.com/orders/1
Resource representation – This is how the resource will return to the client. This representation can be in HTML, XML, JSON, TXT, and more. Clients interact with a service by exchanging representations of resources. Many web APIs use JSON as the exchange format. For example, a GET request to the URI listed above might return this response body:
{"orderId":1,"orderValue":99.90,"productId":1,"quantity":1}

Self-descriptive Messages

Each message includes enough information to describe how to process the message. Beyond what we have seen so far, the passage of meta information is needed (metadata) in the request and response. Some of this information are: HTTP response code, Host, Content-Type etc. Taking as an example the same URI as we have just seen:
GET /#!/user/ramesh HTTP/1.1
User-Agent: Chrome/37.0.2062.94
Accept: application/json
Host: exampledomain.com

Hypermedia as the Engine of Application State (HATEOAS)

REST APIs are driven by hypermedia links that are contained in the representation. For example, the following shows a JSON representation of an order. It contains links to get or update the customer associated with the order.
Just one example:
{
    "orderID":3,
    "productID":2,
    "quantity":4,
    "orderValue":16.60,
    "links": [
        {"rel":"product","href":"http://adventure-works.com/customers/3", "action":"GET" },
        {"rel":"product","href":"http://adventure-works.com/customers/3", "action":"PUT" } 
    ]
} 

Layered System

The server can have multiple layers for implementation. This layered architecture helps to improve scalability by enabling load balancing. It also improves the performance by providing shared caches at different levels.
Figure: Layered System
By applying a layered system constraint:

  • Similar to the client-server constraint this constraint improves simplicity by separating concerns.
  • Can be used to encapsulate legacy services or protect new services from legacy clients.
  • Intermediaries can be used to improve system scalability by enabling load balancing
  • Placing shared caches at the boundaries of the organizational domain can result in significant benefits. Can also enforce security policies e.g. firewall.
  • Intermediaries can actively transform message content since messages are self-descriptive and their semantics are visible to the intermediaries Tradeoff: Adds overhead and latency and reduce user-perceived performance.

Code on Demand

This constraint is optional. This constraint indicates that the functionality of the client applications can be extended at runtime by allowing a code download from the server and executing the code. Some examples are the applets and the JavaScript code that get transferred and executed at the client-side at runtime.
Figure: Code on demand

By applying Code on demand constraint:
  • Simplifies clients, hence promote the reduced coupling of features.
  • Improves scalability by virtue of the server off-loading work onto the clients.
  • Trade-off: Reduces visibility generated by the code itself, which is hard for an intermediary to interpret.

Conclusion

In this post, we have seen the 6 important REST Architectural Constraints.

Now we understand that these 6 architectural constraints which make any web service – a truly RESTful API.

These constraints of the REST architectural style affect the following REST architectural properties.

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours


Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course

Comments

  1. Happy to chat on your blog, I feel like I can't wait to read more reliable posts and think we all want to thank many blog posts to share with us.

    Data Science in Bangalore

    ReplyDelete
  2. A good blog always contains new and exciting information and as I read it I felt that this blog really has all of these qualities that make a blog.

    Data Analytics Course in Patna

    ReplyDelete

  3. Very informative message! There is so much information here that can help any business start a successful social media campaign!Data Analytics Course in Kolkata

    ReplyDelete
  4. I couldn't leave your website until I told you that I really appreciated the high quality information it presents to your visitors. I will come back frequently to check for new posts.

    Data Scientist Course in Durgapur

    ReplyDelete
  5. It's like you've got the point right, but forgot to include your readers. Maybe you should think about it from different angles.

    Data Science Course in Gorakhpur

    ReplyDelete
  6. A good blog always contains new and exciting information and as I read it I felt that this blog really has all of these qualities that make a blog.
    Data Science Institutes in Bangalore

    ReplyDelete
  7. Very informative message! There is so much information here that can help me thank you for sharing
    Data Analytics Course in Chandigarh

    ReplyDelete
  8. Excellent effort to make this blog more wonderful and informative. The information shared was very useful.
    Data Analytics Course in Chandigarh

    ReplyDelete
  9. I'm always looking online for articles that can help me. I think you also made some good comments on the functions. Keep up the good work!



    Data Scientist Course in Bangalore

    ReplyDelete
  10. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. Keep up the good work. Waiting for your next article
    Business Analytics Course in Jabalpur

    ReplyDelete
  11. Very educating blog, got lot of information thank you.
    Data Scientist Course in Amritsar

    ReplyDelete
  12. Very useful message. This is my first time visiting here. I found a lot of interesting things on your blog, especially your discussion. It really is a great article. Keep on going.

    Data Analytics Course in Ernakulam

    ReplyDelete
  13. It's like you've got the point right, but forgot to include your readers. Maybe you should think about it from different angles.

    Data Scientist Course Syllabus

    ReplyDelete
  14. Very useful article to read and Information was helpful.I would like to thank you for the efforts you had made for writing this awesome article.
    Data Analytics Course

    ReplyDelete
  15. It's like you've got the point right, but forgot to include your readers. Maybe you should think about it from different angles.


    Best Data Science Courses in Bangalore

    ReplyDelete
  16. Really impressed! Everything is a very open and very clear clarification of the issues. It contains true facts. Your website is very valuable. Thanks for sharing.

    Best Data Analytics Courses in Bangalore

    ReplyDelete
  17. Very informative message! There is so much information here that can help any business start a successful social media campaign!
    Data Analytics Bangalore

    ReplyDelete
  18. It's like you've got the point right, but forgot to include your readers. Maybe you should think about it from different angles.

    Business Analytics Course in Nashik

    ReplyDelete
  19. I was curious if you ever thought of changing the layout of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 pictures. Maybe you could space it out better?|data analytics course in jodhpur

    ReplyDelete
  20. Hi, This article is probably where I got the most useful information for my research. Do you know of any other websites on this topic?
    Data Science Training in Ahmedabad

    ReplyDelete
  21. I read your excellent post. It's a great job. I enjoyed reading your post for the first time. I want to thank you for this publication. Thank you...

    Data Analytics Course in Patna

    ReplyDelete
  22. I have bookmarked your site since this site contains significant data in it. You rock for keeping incredible stuff. I am a lot of appreciative of this site.

    ReplyDelete
  23. 360DigiTMG, the top-rated organisation among the most prestigious industries around the world, is an educational destination for those looking to pursue their dreams around the globe. The company is changing careers of many people through constant improvement, 360DigiTMG provides an outstanding learning experience and distinguishes itself from the pack. 360DigiTMG is a prominent global presence by offering world-class training. Its main office is in India and subsidiaries across Malaysia, USA, East Asia, Australia, Uk, Netherlands, and the Middle East.

    ReplyDelete
  24. Wonderful illustrated information. Thank you. It will certainly be very useful for my future projects. I would love to see more articles on the same topic!

    Data Science Training in Bangalore

    ReplyDelete
  25. It would also motivate almost everyone to save this webpage for their favorite helper to help get the look published.

    Data Science Training in Patna

    ReplyDelete
  26. Superb Information, I really appreciated with it, This is fine to read and valuable pro potential, I really bookmark it, pro broaden read. Appreciation pro sharing. I like it.Data Analytics Course in Dombivli

    ReplyDelete
  27. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts. business analytics course in surat

    ReplyDelete
  28. Good blog and absolutely exceptional. You can do a lot better, but I still say it's perfect. Keep doing your best.

    Data Science Training in Durgapur

    ReplyDelete
  29. It's like you've got the point right, but forgot to include your readers. Maybe you should think about it from different angles.

    Data Analytics Course in Erode

    ReplyDelete
  30. Very informative message! There is so much information here that can help any business start a successful social media campaign!

    Business Analytics Course in Gorakhpur

    ReplyDelete
  31. I have read your article, it is very informative and useful to me, I admire the valuable information you offer in your articles. Thanks for posting it ...

    Business Analytics Course in Ernakulam

    ReplyDelete
  32. Thanks for the informative and helpful post, obviously in your blog everything is good.
    data science course

    ReplyDelete
  33. I read your excellent blog post. It's a great job. I enjoyed reading your post for the first time, thank you.
    Data Science Institutes in Bangalore

    ReplyDelete
  34. Very informative message! There is so much information here that can help any business start a successful social media campaign!

    Business Analytics Course

    ReplyDelete
  35. I want to thank you for your efforts in writing this article. The information provided was very useful.
    Data Science Certification Bangalore

    ReplyDelete
  36. Very informative message! There is so much information here that can help any business start a successful social media campaign!


    Data Scientist Course Syllabus

    ReplyDelete
  37. I am always searching online for articles that can help me and you made some good points in Features also. Keep working, great job
    Data Science Training

    ReplyDelete
  38. I truly appreciate just perusing the entirety of your weblogs. Just needed to educate you that you have individuals like me who value your work. Unquestionably an extraordinary post. Caps off to you! The data that you have given is exceptionally useful.data scientist course in bhopal

    ReplyDelete
  39. Nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
    data scientist course in malaysia

    ReplyDelete
  40. Well done for this excellent article. and really enjoyed reading this article today it might be one of the best articles I have read so far and please keep this work of the same quality.
    Data Analytics Course in Noida

    ReplyDelete
  41. Someone Sometimes with visits your blog regularly and recommended it in my experience to read as well.Data Science Course in Dombivli

    ReplyDelete
  42. I am sure it will help many people. Keep up the good work. It's very compelling and I enjoyed browsing the entire blog.
    Business Analytics Course in Bangalore

    ReplyDelete
  43. Nice Post i have read this article and if I can I would like to suggest some cool tips or advice and perhaps you could write future articles that reference this article. I want to know more!
    Data Analytics Course in Gurgaon

    ReplyDelete
  44. I was surfing the net and luckily I came across this site and found some very interesting things here. It's a lot of fun to read. I really enjoyed it. Thank you for sharing this wonderful information.

    Business Analytics Course in Durgapur

    ReplyDelete
  45. I always search online for articles that can help me. Obviously, there is a lot to know about this. I think you made a few good points about the features as well. Keep up the good work!

    Data Scientist Course in Ernakulam

    ReplyDelete
  46. 360DigiTMG delivers the best Data Analytics course with placements. Top industry trainers, LMS access, world-class curriculum, mock interviews, and guidance sessions for resume preparation.Data Analytics Course in Faridabad

    ReplyDelete
  47. 360DigiTMG offers the best Data Analytics courses in the market with placement assistance and live projects. Enroll today and become a Data Science professional in the next 6 months.Data Analytics Course in Chandigarh

    ReplyDelete
  48. Are you looking for a Data Science course that will introduce you to all the fundamental concepts with a practical approach. 360DigiTMG is the right place for you. for more details click the link below.business analytics course in Durgapur

    ReplyDelete
  49. Are you looking for a Data Science course that will introduce you to all the fundamental concepts with a practical approach. 360DigiTMG is the right place for you. for more details click the link below.business analytics course in Trichy

    ReplyDelete
  50. Don't let pandemic affect your career growth, become a successful Data Scientist with the best course offered online at 360DigiTMG.business analytics course in rourkela

    ReplyDelete
  51. Are you searching for the best Data Science certification online with placement assistance then 360DigiTMG is the best institute for you. Enroll today!data analytics course in meerut

    ReplyDelete
  52. Are you looking for a Data Science training institute that will not only train you but also aid you in bagging a job, 360DigiTMG is the right place for you.
    business analytics course in trichy

    ReplyDelete
  53. Without data analytics, you cannot imagine data science. In this process, data is examined to transform it into a meaningful aspect.

    data science course in patna

    ReplyDelete
  54. Embark on a journey to achieve your professional goals by enrolling in the Data Scientist course in Bangalore. Learn the skills of collecting, extracting, analyzing, preparing, visualizing, and presenting results to make valuable decisions. Master the concepts of data science through hands-on projects and case studies to learn the latest trends and skills in this field.

    Best Data Science Institute in Bangalore

    ReplyDelete
  55. When one thinks about data science, there might be word machine learning comes into the mind.data science course in nashik

    ReplyDelete
  56. Register for the Data Science certification in Bangalore and gain recognition and credibility in your organization. Learn the techniques to examine large data sets and discover patterns that are valuable to predict market trends. Learn Data Exploration and Visualizations, Neural Networks and Deep Learning, Model Evaluation and Analysis. This course will ensure that you are challenged to go from a beginner with no Data Science experience to someone who can juggle data with ease.

    Data Science Training and Placement in Bangalore

    ReplyDelete
  57. Gain expertise in the relevant and current practices, challenges, and research involved in the field of Data Science. Learn all the skills from non-coding essentials to data science and machine learning by enrolling in the Data Science course in Bangalore. Using real data sets across a range of domains enhances your skills in supervised and unsupervised learning, neural networks, sampling techniques, support vector machines, and more. Get certified in Data Science to get one step ahead towards a lucrative career.


    Data Science Course in Bangalore with Placement

    ReplyDelete

Post a Comment