Rest之路 - Rest架构中的重要概念

资源

在Rest的架构之内,讲一切内容都是为资源。每一个资源都被定义为一个URI。

格式: <protocol>://<service-name>/<ResourceType>/<ResourceID>

除此之外,URI的另一个关键部分为“VERB“, 相应的我们也称他们为“方法”。他们通常有四种形式 -- GET/POST/PUT/UPDATE

 

关于资源的表述,Rest有多种形式的表述方式,其中以XML和JSON最为常用。

 

消息

Rest 采用HTTP协议作为client和server之间的传输媒介。 client 通过发送 HTTP Request 到 Server;Server 发送 HTTP Response 到 client。

为了方便理解,通过图文并茂的方式来解释一下 HTTP Request/Response.

以下部分摘自: https://www.tutorialspoint.com/restful/restful_messages.htm

HTTP Request

HTTP Request

A HTTP Request has five major parts:

  • Verb- Indicate HTTP methods such as GET, POST, DELETE, PUT etc.

  • URI- Uniform Resource Identifier (URI) to identify the resource on server

  • HTTP Version- Indicate HTTP version, for example HTTP v1.1 .

  • Request Header- Contains metadata for the HTTP Request message as key-value pairs. For example, client ( or browser) type, format supported by client, format of message body, cache settings etc.

  • Request Body- Message content or Resource representation.

HTTP Response

HTTP Response

A HTTP Response has four major parts:

  • Status/Response Code- Indicate Server status for the requested resource. For example 404 means resource not found and 200 means response is ok.

  • HTTP Version- Indicate HTTP version, for example HTTP v1.1 .

  • Response Header- Contains metadata for the HTTP Response message as key-value pairs. For example, content length, content type, response date, server type etc.

  • Response Body- Response message content or Resource representation.

Example

As we have explained in RESTful Web Services - First Application tutorial, Let's put http://localhost:8080/UserManagement/rest/UserService/users in POSTMAN with GET request. If you click on Preview button residing near send button of Postman and then click on Send button, you may see the following output.

HTTP Request/Response

Here you can see, the browser sent a GET request and received a response body as XML.

posted @   TonyZhang24  阅读(398)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示