当前位置:网站首页>What is a RESTful API?
What is a RESTful API?
2022-07-30 19:02:00 【HUAWEI CLOUD】

RESTful API An interface used by two computer systems to securely exchange information over the Internet.Most business applications must communicate with other internal and third-party applications to perform various tasks.
例如,To generate monthly payroll,Your internal account system must share data with your customer's banking system to automatically invoice and communicate with your internal timesheet application.
RESTful API This type of information exchange is supported,Because they follow safety、Reliable and efficient software communication standard.
什么是 API?
应用程序编程接口(API)Define the rules you must follow to communicate with other software systems.Developers expose or create API,so that their application can communicate with other applications programmatically.例如,The Timesheet application exposes a request for the employee's full name and date range API.when it receives this information,It processes the employee's timesheet internally,and returns the number of hours worked for that date range.
您可以将 Web API Imagine as client and Web on the gate between resources.
客户端
The client is to access Web users who posted the information.客户端可以是使用 API personal or software systems.例如,Developers can write programs that access weather data from the weather system.或者,You can access the same data by visiting the Weather website directly on your browser.
资源
Resources are information that different applications provide to their clients.Resources can be images、视频、文本、numbers or any kind of data.A device that provides resources to clients is also called a server.企业使用 API 分享资源,既能提供 Web 服务,Also ensure safety、可控,身份验证.此外,API Helps businesses determine which clients can access specific internal resources.
什么是 REST?
表征状态传输 (REST) 是一种软件架构,决定了 API 的工作条件.REST Originally used to manage complex networks(例如互联网)established by the guidelines on communication.您可以使用基于 REST The architecture provides support for high performance and reliable large-scale communication.You can easily apply and modify this architecture,为任何 API The system brings visibility and cross-platform possibilities.
API Developers can use a number of different architectural designs API.遵循 REST 架构风格的 API 称为 REST API.实施 REST 架构的 Web 服务称为 RESTful Web 服务.术语 RESTful API 通常指 RESTful Web API.但是,术语 REST API 和 RESTful API 可以互换使用.
以下是 REST Some principles of architectural style:
统一接口
Unified Interface is everything RESTful Web Fundamentals of Service Design.It means that the server transmits the information in a standard format.The formatted resource is in REST is called representation.This format can differ from the internal representation of the resource on the server application.例如,The server can store data as text,但以 HTML This data is sent in the characterization format.
The unified interface enforces four architectural constraints:
- The request should identify the resource.They do this by using uniform resource identifiers.
- The client contains enough information in the resource representation to modify or delete the resource(如需要).The server complies with this condition by sending metadata that further describes the resource.
- The client receives information on how to further process the representation.The server does this by sending self-describing information,This information contains metadata about how clients can best use this information.
- The client receives information about all other related resources it needs to complete its task.The server does this by sending a hyperlink in the representation,so that clients can dynamically discover more resources.
无状态
在 REST 架构中,Stateless refers to a method of communication where the server completes each client request independently of all previous requests.Clients can request resources in any order,Each request is stateless or independent of other requests.此 REST API Design constraints mean that the server can fully recognize and fulfill the request every time.
Rest 动词
REST 动词指定要对特定资源或资源集合执行的操作.当客户端发出请求时,它应该在 HTTP 请求中发送以下信息:
- REST 动词
- 头信息
- 主体(可选)
REST 使用 URI 来解码其要处理的资源.有很多可用的 REST 动词,但其中有六个是经常使用的.它们如下:
-
GET:客户端使用 GET Access is specified on the server URL 上的资源.They can be cached GET 请求,并在 RESTful API Parameters are sent in the request to instruct the server to filter the data before sending. -
POST:客户端使用 POST 向服务器发送数据.They include data representations into the request.Send the same multiple times POST Requests have the undesirable effect of creating the same resource multiple times. -
PUT:客户端使用 PUT Update existing resources on the server.与 POST 不同,在 RESTful Web The same is sent multiple times in the service PUT request has the same effect. -
PATCH:Used to modify the value of a resource property.Can be used to update some resources.例如,When you only need to update one field of a resource,Placing a full resource representation can be cumbersome,and use more bandwidth -
DELETE:客户端使用 DELETE 请求删除资源.DELETE Requests can change server state.但是,If the user does not have proper authentication,则请求失败. -
OPTIONS:是方法级别的注释,This annotation indicates that the following method will only respondHTTP选项请求.it is used to request,for information about the communication options available for the resource.
Sr.No. | URI | HTTP Method | POST body | Result |
1 | /UserService/users | GET | empty | Show list of all the users. |
2 | /UserService/addUser | POST | JSON String | Add details of new user. |
3 | /UserService/getUser/:id | GET | empty | Show details of a user. |
URL,Unique resource identifier
The server identifies each resource by a unique resource identifier.对于 REST 服务,Servers typically use Uniform Resource Locators (URL) Perform resource identification.URL 指定资源的路径.URL Similar to the website address you enter into your browser when you visit any web page.URL Also called request endpoint,And clearly indicate to the server what the client is requesting.
HTTP 头
Request headers are metadata exchanged between client and server.例如,Request headers indicate the format of the request and response,Provides information about the status of the request and more.
数据
REST API 请求可能包含 POST、PUT 和其他 HTTP The data required for the method to run successfully.
参数
RESTful API Requests can contain parameters,These parameters provide the server with more details about what action to take.Below are some of the different types of parameters:
- 指定 URL Path parameter for details.
- Query parameters to request more information about the resource.
- Fast authentication of clients Cookie 参数.
边栏推荐
- Swiper rotates pictures and plays background music
- 中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
- 2种手绘风格效果比较,你更喜欢哪一种呢?
- Does the satellite phone communicate directly with the satellite or through a ground station?
- Pytorch foundation -- tensorboard use (1)
- 什么是 RESTful API?
- 实体中增加操作方法
- MySQL数据类型
- 《痞子衡嵌入式半月刊》 第 59 期
- Recommendation | People who are kind to you, don't repay them by inviting them to eat
猜你喜欢

NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...

Codeblocks + Widgets 创建窗口代码分析

开心的聚餐

node封装一个控制台进度条插件

线性筛求积性函数

432.4 FPS 快STDC 2.84倍 | LPS-Net 结合内存、FLOPs、CUDA实现超快语义分割模型

防抖和节流有什么区别,分别用于什么场景?

【剑指 Offer】剑指 Offer 22. 链表中倒数第k个节点

(2022杭电多校四)1001-Link with Bracket Sequence II(区间动态规划)

Node encapsulates a console progress bar plugin
随机推荐
不同的路径依赖
尊重客观事实
Scrapy框架介绍
自己需要努力
【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list
深化校企合作 搭建技术技能人才成长“立交桥”
荐号 | 对你有恩的人,不要请吃饭来报答
7.29模拟赛总结
博纳影通过IPO注册:阿里腾讯是股东 受疫情冲击明显
Codeblocks + Widgets 创建窗口代码分析
【Swords Offer】Swords Offer 17. Print n digits from 1 to the largest
natural language processing nltk
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
golang日志库zerolog使用记录
Critical Reviews | 南农邹建文组综述全球农田土壤抗生素与耐药基因分布
中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
The use of @ symbol in MySql
2种手绘风格效果比较,你更喜欢哪一种呢?
电脑死机的时候,发生了什么?
Mysql执行原理剖析