In a RESTful
architecture, the focus is on resources. Standard methods are used to retrieve and manipulate information fragments when operating on resources. In an RPC
architecture, the focus is on methods. Server methods are invoked in the same manner as invoking local methods.
REST
stands for Representational State Transfer, which is a software architectural style and can also be referred to as a pattern for designing APIs. REST
uses HTTP protocol to define general verb methods such as GET
, POST
, PUT
, DELETE
, and it uniquely identifies network resources via URIs. The response side, based on the different requirements of the request side, represents the requested resource through stateless communication. An architecture that conforms to the REST
design specifications is referred to as RESTful
.
xml
, json
, etc.Security refers to accessing REST
interfaces without causing changes to the server's resource state. Idempotent means that when the same REST
interface URI is accessed multiple times, the resource state obtained is the same.
GET
: Safe and idempotent, used to read a resource.POST
: Not safe and not idempotent, used to create resources with automatically generated instance numbers on the server, and to update partial resources.PUT
: Not safe and idempotent, used to create resources and update resources with instance numbers on the client side.DELETE
: Not safe and idempotent, used to delete resources with instance numbers on the client side.user
, GET https://127.0.0.1/user/1
, directly carry params
to query the user.user
, POST https://127.0.0.1/user
, include user registration information in the request body
.user
, PUT https://127.0.0.1/user
, include the userid
identification information in the request body
.user
, DELETE https://127.0.0.1/user
, include the userid
identification information in the request body
.Accept
to obtain different forms of the same resource, such as application/json
and application/xml
.Accept
field instead of directly adding the version number to the URI
.RPC
stands for Remote Procedure Call, which can be simply understood as one node requesting a service provided by another node. Remote procedure call is in contrast to local procedure call. When calling a method, the method on the remote server is invoked in the same manner as calling a local method, achieving lightweight and transparent communication.
RESTful
uses the HTTP
protocol for data transmission, while RPC
generally uses the TCP
protocol for data transmission. However, the transmission protocol is not the focus of RPC
. Typically, TCP
protocol is used for its high efficiency, while using HTTP
protocol for transmission is completely feasible.RPC
is higher than that of RESTful
because RPC
has an efficient and compact inter-process communication mechanism and transmits small amounts of data, resulting in higher efficiency when exchanging large amounts of messages.RESTful
architecture is higher than that of the RPC
architecture. Using the RESTful
architecture provides better readability, while RPC
is slightly cumbersome to write and debug.RESTful
architecture for data transmission provides multi-language support. The HTTP
protocol is relatively more standardized, universal, and standard. For middleware, the first supported protocols usually include the RESTful
data transmission specification.RPC
for internal service invocation, while RESTful
is recommended for external interfaces. For example, the microservices architecture pattern generally adopts the RPC
for internal and RESTful
for external communication pattern.