当前位置:网站首页>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 参数.
边栏推荐
- DM8:单库单实例搭建本地数据守护服务
- The use of terminal split screen tool Terminalx
- Recommendation | People who are kind to you, don't repay them by inviting them to eat
- NC | 西湖大学陶亮组-TMPRSS2“助攻”病毒感染并介导索氏梭菌出血毒素的宿主入侵...
- Pytorch foundation -- tensorboard use (1)
- 什么是 RESTful API?
- Scrapy框架介绍
- Spark学习:编译Spark项目时遇到的报错
- Mysql execution principle analysis
- 攻防世界web-Cat
猜你喜欢
【剑指 Offe】剑指 Offer 18. 删除链表的节点
开心的聚餐
基于inquirer封装一个控制台文件选择器
【PHPWord】Quick Start of PHPWord in PHPOffice Suite
C# wpf 无边框窗口添加阴影效果
nlohmann json 使用指南【visual studio 2022】
- daily a LeetCode 】 【 191. A number of 1
CCNA-NAT协议(理论与实验练习)
Does the satellite phone communicate directly with the satellite or through a ground station?
Codeblocks + Widgets 创建窗口代码分析
随机推荐
7.29模拟赛总结
一文读懂“语言模型”
解决终极bug,项目最终能顺利部署上线。
What is the value of biomedical papers? How to translate the papers into Chinese and English?
VBA 运行时错误‘-2147217900(80040e14):自动化(Automation)错误
Anaconda Navigator stuck on loading applications
LeetCode 练习——关于查找数组元素之和的两道题
OneFlow source code analysis: Op, Kernel and interpreter
Common linked list problems and their Go implementation
生物医学论文有何价值 论文中译英怎样翻译效果好
【Prometheus】Prometheus联邦的一次优化记录[续]
SimpleOSS第三方库libcurl与引擎libcurl错误解决方法
AI Basics: Graphical Transformer
"Ruffian Heng Embedded Bimonthly" Issue 59
- daily a LeetCode 】 【 191. A number of 1
经济新闻:错误# 15:初始化libiomp5md。dll,但发现libiomp5md。已经初始化dll。解决方法
你好,我的新名字叫“铜锁/Tongsuo”
Immersive experience iFLYTEK 2022 Consumer Expo "Official Designated Product"
高并发秒杀项目总结
Hello, my new name is "Bronze Lock/Tongsuo"