Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET WebAPI #27

Open
Henrik-Xu opened this issue May 27, 2019 · 0 comments
Open

ASP.NET WebAPI #27

Henrik-Xu opened this issue May 27, 2019 · 0 comments

Comments

@Henrik-Xu
Copy link
Owner

Henrik-Xu commented May 27, 2019

ASP.NET WebAPI2

什么是 ASP.NET-WebAPI

ASP.NET Web API 是一种框架,用于轻松构建可以访问多种客户端(包括浏览器和移动设备)的 HTTP

服务。

ASP.NET Web API是一种用于在 .NET Framework 上构建RESTful 应用程序的理想平台。

关于RESTful的理解

1.REST 是英文 representational state transfer(表象性状态转变)或者表述性状态转移; Restweb

务的一种架构风 格; 使用HTTP,URI,XML,JSON,HTML等广泛流行的标准和协议;轻量级,跨平台,跨语言

的架构设计; 它是一种设计风格,不是一种标准,是一种思想。

2.Rest 架构的主要原则:

  • 事务为对象,资源有统一,形式有多样(xmljson 等)

  • 每个资源都有一个唯一的资源标识符。

  • 同一个资源具有多种表现形式(xml,json 等)。

  • 对资源的各种操作不会改变资源标识符。

  • 所有的操作都是无状态的。

  1. 什么叫 rest api ? 在 url 上有什么特点?

REST API 是把服务器数据和功能抽象成资源并通过 HTTP 方法进行操作的一种 API 设计风格。

根据 Url 就知道要什么:http://example.com/resources/1

根据 http method 就知道干什么:OPTIONS/GET/PUT/POST/DELETE

根据 http status code 就知道结果如何:2xx、3xx、4xx、5xx

资源描述和操作的分离,所有的数据和功能都被命名成一种资源,并通过 HTTP 的方法操作这些资源。

4.为什么会出现 restful

Restful 之前我们写一个 web 请求,格式通常是这样的:

  • "/product/query/1" 根据用户 id 查询商品

  • "/product/Add" 新增商品

  • "/product/update" 修改商品

  • "/product/delete" 删除商品

Restful 用法:

  • "/product/1" GET 根据用户 id 查询商品

  • "/product/" POST 新增商品

  • "/product/" PUT 修改商品

  • "/product/" DELETE 删除商品

restful 风格其实就是根据请求的类型(getpostputdelete)来匹配对应的方法。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant