Rest之路 - Rest架构中的重要概念(二)
状态无关性
Rest 架构中不维持client,resource and request 的状态,我们通常称 Rest 服务是状态无关的。基于此的优势是为设计Rest架构提供了简便;每一个请求可以被完全单独的处理;与HTTP协议的状态无关保持一致。不足之处在于但是如果需要获取或者维持状态,需要消耗额外的资源。
缓存
缓存的设计是为了减少server端的负担,client 不需要每次都向 server 发送请求,client可以使用缓存技术来保存 server response。
HTTP Code:
S.N. | HTTP Code & Description |
---|---|
1 | 200 OK, shows success. |
2 | 201 CREATED, when a resource is successful created using POST or PUT request. Return link to newly created resource using location header. |
3 | 204 NO CONTENT, when response body is empty for example, a DELETE request. |
4 | 304 NOT MODIFIED, used to reduce network bandwidth usage in case of conditional GET requests. Response body should be empty. Headers should have date, location etc. |
5 | 400 BAD REQUEST, states that invalid input is provided e.g. validation error, missing data. |
6 | 401 UNAUTHORIZED, states that user is using invalid or wrong authentication token. |
7 | 403 FORBIDDEN, states that user is not having access to method being used for example, delete access without admin rights. |
8 | 404 NOT FOUND, states that method is not available. |
9 | 409 CONFLICT, states conflict situation while executing the method for example, adding duplicate entry. |
10 | 500 INTERNAL SERVER ERROR, states that server has thrown some exception while executing the method. |
分类:
Java Web
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现