Client should know only resource URIs and that’s all.
REST Principles and Architectural Constraints – REST API Tutorial https://restfulapi.net/rest-architectural-constraints/
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 lower level, it just put high level design guidelines and leave you to think of your own implementation.
In my last employment, I designed RESTful APIs for telecom major company for 2 good years. In this post, we will be sharing my thoughts apart from normal design practices. You may not be agree with me on few points, and that’s perfectly OK. I will be happy to discuss anything from you with open mind.
Let’s start with standard design specific stuff to clear what ‘Roy Fielding’ wants us to build. Then we will discuss my stuff which will be more towards finer points while you design your RESTful APIs.
Architectural Constraints
REST defines 6 architectural constraints which make any web service – a true RESTful API.
Uniform interface
As the constraint name itself applies, you MUST decide APIs interface for resources inside system which are exposed to API consumers and follow religiously. A resource in system should have only one logical URI, and then should provide way to fetch related or additional data. It’s always better to synonymise a resource with a web page.
Any single resource should not be too large and contain each and everything in it’s representation. Whenever relevant, a resource should contain links (HATEOAS) pointing to relative URIs to fetch related information.
Also, the resource representations across system should follow certain guidelines such as naming conventions, link formats or data format (xml or/and json).
All resources should be accessible through a common approach such as HTTP GET, and similarly modified using consistent approach.
Client–server
This essentially means that client application and server application MUST be able to evolve separately without any dependency
on each other. Client should know only resource URIs and that’s all. Today, this is normal practice in web development so nothing fancy is required from your side. Keep it simple.
Stateless
Roy fielding got inspiration from HTTP, so it reflects in this constraint. Make all client-server interaction stateless. Server will not store anything about latest HTTP request client made. It will treat each and every request as new. No session, no history.
If client application need to be a stateful application for end user, where user logs in once and do other authorized operations thereafter, then each request from the client should contain all the information necessary to service the request – including authentication and authorization details.
Cacheable
In today’s world, caching of data and responses is of utmost important wherever they are applicable/possible. The webpage you are reading here is also a cached version of HTML page. Caching brings performance improvement for client side, and better scope for scalability for server because load has reduced.
In REST, caching shall be applied on resources when applicable and then these resources MUST declare themselves cacheable. Caching can be implemented on server or client side.
Layered system
REST allow you to use a layered system architecture where you deploy the APIs on server A, and store data on server B and authenticate requests in Server C, for example. A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way.
Code on demand (optional)
Well, this constraint is optional. Most of the time you will be sending the static representations of resources in form of XML or JSON. But when you need to, you are free to return executable code
to support a part of your application e.g. clients may call your API to get a UI widget rendering code. It is permitted.
Notice that all above constraints are most closely related to WWW (the web). Using RESTful APIs, you can do the same thing with your web services what you do to web pages.
Client should know only resource URIs and that’s all.的更多相关文章
- REST Representational state transfer REST Resource Naming Guide Never use CRUD function names in URIs
怎样用通俗的语言解释什么叫 REST,以及什么是 RESTful? - 知乎 https://www.zhihu.com/question/28557115 大家都知道"古代"网 ...
- 基于OWIN WebAPI 使用OAuth授权服务【客户端验证授权(Resource Owner Password Credentials Grant)】
适用范围 前面介绍了Client Credentials Grant ,只适合客户端的模式来使用,不涉及用户相关.而Resource Owner Password Credentials Grant模 ...
- Jersey(1.19.1) - Client API, Uniform Interface Constraint
The Jersey client API is a high-level Java based API for interoperating with RESTful Web services. I ...
- Jersey(1.19.1) - Client API, Testing services
The Jersey client API was originally developed to aid the testing of the Jersey server-side, primari ...
- IdentityServer Resource Owner Password
Resource Owner Password 模式需要自己实现用户名密码的校验 新增ResourceOwnerPasswordValidator实现IResourceOwnerPasswordVal ...
- Spring Cloud(6.2):搭建OAuth2 Client
配置web.xml 添加spring-cloud-starter-security,spring-security-oauth2-autoconfigure和spring-boot-starter-o ...
- SpingMVC 核心技术帮助文档
声明:本篇文档主要是用于参考帮助文档,没有实例,但几乎包含了SpringMVC 4.2版本的所有核心技术,当前最新版本是4.3,4.2的版本已经经是很新的了,所以非常值得大家一读,对于读完这篇文档感觉 ...
- http2协议翻译(转)
超文本传输协议版本 2 IETF HTTP2草案(draft-ietf-httpbis-http2-13) 摘要 本规范描述了一种优化的超文本传输协议(HTTP).HTTP/2通过引进报头字段压缩以及 ...
- The OAuth 2.0 Authorization Framework-摘自https://tools.ietf.org/html/rfc6749
Internet Engineering T ...
随机推荐
- 新一代 javascript 模板引擎
artTemplate-3.0 新一代 javascript 模板引擎 <!DOCTYPE html> <html lang="en"> <head& ...
- 【bzoj3689】异或之 可持久化Trie树+堆
题目描述 给定n个非负整数A[1], A[2], ……, A[n].对于每对(i, j)满足1 <= i < j <= n,得到一个新的数A[i] xor A[j],这样共有n*(n ...
- 两周多学完Java 23种设计模式
最近两周任务不是很繁重,对于一个刚入职4个月的菜鸟来说,学习设计模式并灵活使用简直天方夜谭:但是当我询问我导师需要学点啥的时候?“<Java设计模式>,这个必须要学”,一句简单粗略的 ...
- [BZOJ4992] [Usaco2017 Feb]Why Did the Cow Cross the Road(spfa)
传送门 把每个点和曼哈顿距离距离它3步或1步的点连一条边,边权为3 * t + a[x][y] 因为,走3步,有可能是3步,也有可能是1步(其中一步拐了回来) 最后,把终点和曼哈顿距离距离它1步和2布 ...
- 刷题总结——选课(ssoj树形dp+记忆化搜索+多叉树转二叉树)
题目: 题目描述 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了 N(N<300)门的选修课程,每个学生可选课程的数量 M 是给定的.学生选修了这M门课 ...
- Spoj-BLMIRINA Archery Training
Mirana is an archer with superpower. Every arrow she shoots will get stronger the further it travels ...
- ElasticSearch集群状态查看命令大全
Elasticsearch中信息很多,同时ES也有很多信息查看命令,可以帮助开发者快速查询Elasticsearch的相关信息. _cat $ curl localhost:9200/_cat =^. ...
- Scrapy学习-8-ItemLoader
ItemLoader使用 作用 方便管理维护重用xpath或css规则 实例 itemloader+图片处理 # items.py import scrapy from scrapy.loader ...
- Windows下,RabbitMQ安装、卸载以及遇到的坑
RabbitMQ是目前比较使用比较广泛的一个队列服务器,但是很多朋友在使用过程中,也遇到一些问题,这篇文章主要是做一个总结吧 本篇文章,虽然标题命名为“安装与卸载”,但是网上有很多类似的文章,我就简单 ...
- Set 技巧之一
我们知道set中 用set<int,int>S; S.lower_bound(x): 查找Set中 第一个>=x的数,返回结果是指针. S.upper_bound(x):查找Set中 ...