By Wang Chen
The author recently participated in the development of an open-source project: HiMarket. This open-source project aims to help developers, especially enterprises, quickly implement a private AI open platform, focusing on managing API and MCP services offered externally. Therefore, this opportunity has been used to summarize the functions and application scenarios of mainstream API protocols in order to clarify easily confused concepts.
API (Application Programming Interface) is, as the name suggests, used to connect different software systems to achieve data exchange and service sharing. In composition, it is a set of specifications or protocols that define how different applications or components interact with each other. The core capabilities of an API can be defined with three keywords: defining rules, decoupling systems, and enhancing reusability.
Broadly speaking, we can also view APIs as a kind of middleware that allows developers to access and use certain features or data without needing to understand the detailed implementation behind it, thereby reducing the complexity of software systems. For example, the OpenAPI provided by Alibaba Cloud offers a series of application programming interfaces that help developers manage resources, data, services, etc. on the cloud via APIs.
With the richness of software forms and application scenarios, the types of APIs are also continuously being enriched. From the early heavyweight SOAP, to the popular RESTful API in the web world, and further to the streaming API in the context of large models, the emergence of each new type corresponds to different engineering solutions under new software forms. This article aims to summarize the positioning, functions, and application scenarios of mainstream APIs to help developers gain a comprehensive understanding of API protocols.
Different perspectives lead to different classification methods. This article categorizes APIs into six types based on application scenarios.
REST (Representational State Transfer) is the most widely used architectural style today. It is based on the HTTP protocol and defines a set of design constraints and principles. Its core idea is that everything is a resource, which can be manipulated through a unified interface. Resources are represented by URLs, and operations are defined by HTTP methods (GET/POST/PUT/DELETE). APIs built on REST are referred to as RESTful APIs.
In the web world, resources usually correspond to a URL. For example:
https://api.example.com/users/123 → represents a user resourcehttps://api.example.com/orders/456/items → represents the product resource in an orderJust like every house in the physical world has a unique address. Common open platforms like WeChat, Alipay, and Gaode provide API services that are RESTful.
A typical REST call is divided into two parts: client request and server response:
/users/123
GET for querying, PUT for updatingContent-Type: application/json), authentication token (Authorization: Bearer ...)POST/PUT requests, typically contains JSON dataRequest example:
POST /users HTTP/1.1
Host: api.example.com
Content-Type: application/json
Authorization: Bearer <token>
{
"name": "望宸",
"role": "engineer"
}
200 OK, 201 Created, 404 Not Found
Response example:
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": 123,
"name": "望宸",
"role": "engineer"
}
REST's design philosophy meets the explosive demand of internet applications: lightweight, intuitive, cross-language, and easily extensible. Coupled with the specifications of Swagger (now known as OpenAPI Specification, OAS), it has become the most widely used API form in the internet world, serving as the de facto standard for the Web API protocol.
However, as application scenarios diversify, it has gradually exposed some limitations, thus leading to the emergence of other API forms.
In the context of mobile internet and frontend complexity, there may be mismatches between the data structures required by the client and the RESTful responses returned by the backend.
/users/123 returns the entire user object (containing address, orders, permissions, and a lot more information). This not only wastes bandwidth but also increases parsing overhead./users/123 first, then /users/123/orders, and finally must filter. One page may require three or four requests, affecting performance and latency.This inadequacy is especially serious in mobile, complex single-page applications, and cross-platform applications, as the client side and network environment have limited resources. GraphQL was developed precisely to solve this issue. It allows clients to “fetch data on demand,” returning only the fields needed in one request.
GraphQL, developed by Facebook and open-sourced in 2015, is a query language and execution engine for APIs. Its core idea is that the client decides what data it wants, and the server only returns the required fields.
In contrast to RESTful's resource-based categorization, GraphQL has a single unified entry point (usually /graphql), and clients use query statements (Queries) to specify the data structure precisely. To illustrate the differences between GraphQL and RESTful:
/graphql, simplifying routing and maintenance.GraphQL operates in three steps:
Example of Client Request
POST /graphql HTTP/1.1
Host: api.example.com
Content-Type: application/json
{
"query": "{
user(id: 123) {
name
max
orders(limit: 3) {
id
total
}
}
}"
}
Example of Server Response
{
"data": {
"user": {
"name": "望宸",
"max": "https://cdn.example.com/max/123.png",
"orders": [
{ "id": "A001", "total": 99.9 },
{ "id": "A002", "total": 58.0 },
{ "id": "A003", "total": 199.5 }
]
}
}
}
As can be seen: The client only asks for "avatar, nickname, and three orders"; the server will not give an extra byte.
In cases where performance requirements are not high, RESTful is sufficiently useful. However, as we enter the realm of microservices, the issues become complex:
Here, we introduce three familiar high-performance remote calling frameworks or paradigms for microservice architecture.
Apache Dubbo, open-sourced by Alibaba, is an RPC (Remote Procedure Call) framework. Core features include:
As a variant of the RPC architecture, gRPC was created by Google in 2015 and offers higher performance and lower latency characteristics compared to RESTful APIs.
In the Spring Cloud system, initial remote calls primarily relied on REST (based on HTTP), using RestTemplate or later recommended WebClient. Subsequently, Feign (a declarative HTTP client) emerged, allowing developers to call remote services using interfaces + annotations, making it closer to an RPC development experience.
To illustrate, RESTful is highway transportation (HTTP + JSON), flexible but prone to traffic jams as volume increases; RPC is well-built high-speed rail tracks, where the trains operate efficiently and predictably, suitable for large-scale point-to-point communication.
Real-time performance is a must-have in many internet application scenarios. For instance:
If we only rely on the request-response model of RESTful APIs, the client either needs to constantly poll the server or can only passively wait. The former wastes resources, while the latter fails to meet real-time requirements. Therefore, WebSocket was born, providing the capability for the server to actively push messages to the client, though the methods and applicable scenarios differ.
WebSocket is a full-duplex communication protocol defined in the HTML5 standard, allowing clients and servers to exchange data bidirectionally and in real-time over a single TCP connection. Unlike REST, WebSocket is not a one-time request-and-response short communication; once a connection is established, messages can be exchanged at any time.
Upgrade: websocket);Example
const socket = new WebSocket("ws://example.com/chat");
socket.onopen = () => socket.send("Hello!");
socket.onmessage = (event) => console.log(event.data);
In large model scenarios, traffic exhibits the following characteristics:
Therefore, RESTful is unsuitable, as it requires the client to issue a request, wait for the server to finish computing, and then return results all at once. WebSocket requires bidirectional communication, involving independent protocol upgrades, long connection management, and heartbeat checks; under complex networks (firewalls, proxies, load balancing), WebSocket is more prone to interruption, and its bidirectional capabilities appear redundant, making it not the optimal choice.
SSE (Server-Sent Events) is a one-way streaming transmission mechanism based on HTTP, allowing the server to continuously push event streams to the client through the same connection, naturally fitting scenarios involving dialogue agents.
data: data blocks, allowing the client to receive updates in real-time.Last-Event-ID, it can recover from the interruption point.1. The client initiates an HTTP GET request to the server via EventSource;
2. The server returns Content-Type: text/event-stream and keeps the connection open;
3. The server continuously pushes events in a streaming format:
data: hello
data: world
4. The client processes them one by one, creating a real-time effect.
Example
const source = new EventSource("/events");
source.onmessage = (event) => console.log("New data:", event.data);
To illustrate the differences between the three: WebSocket is like a phone call, where both parties can interrupt each other at any time. SSE is like a radio broadcast, with the server continuously playing programs and the client tuning in. In contrast, RESTful is like writing a letter, requiring a back-and-forth exchange. Compared to the phone mode of WebSocket, SSE is more lightweight and suitable for unidirectional pushing.
Although both interact with large models, the traffic characteristics of MCP scenarios differ somewhat from those of large model clients. Initially, MCP officially used the SSE protocol, but later changed to the Streamable HTTP protocol.
Issues with HTTP + SSE
The transport process of HTTP + SSE involves communication between the client and server through two main channels.
This leads to the following three issues:
Improvements of Streamable HTTP
Streamable HTTP is a significant upgrade of the MCP protocol, addressing multiple critical issues with the original HTTP + SSE transport method through the following improvements:
/sse endpoint for establishing connections, integrating all communication into a unified endpoint.Thus, compared to SSE, Streamable HTTP shows significant improvements in stability, performance, and client complexity.
The evolution of APIs is a process by which software engineering continuously seeks to address new issues. From the complexities of SOAP, to the simplicity of RESTful, to the flexibility of GraphQL, and from unidirectional HTTP requests to real-time bidirectional communication with WebSocket, and finally to streaming APIs in the context of large models, each form represents a new balance found between performance, flexibility, and real-time capability.
In the future, as AI-native applications continue to diversify, APIs will continue to evolve and will give rise to more demands in API management. Recently, Higress has open-sourced the out-of-the-box AI open platform Himarket, aimed at efficiently and uniformly managing RESTful APIs, MCP services, and other interfaces that provide services, data, and applications. Welcome to try it. For functionality and demo details, please read this article.
If you want to learn more about Alibaba Cloud API Gateway (Higress), please click: https://higress.ai/en/
Right Approach to JSON Log Analysis: A Hands-on Guide to Efficient Practices with Alibaba Cloud SLS
ARMS Continuous Profiling Upgrade for Efficient and Accurate Performance Bottleneck Localization
626 posts | 54 followers
FollowAlibaba Cloud Native Community - July 24, 2025
Alibaba Cloud Native Community - February 8, 2025
Alibaba Cloud Native - August 14, 2024
Aliware - January 4, 2021
Alibaba Cloud Native Community - July 20, 2023
Alibaba Cloud Native Community - August 21, 2023
626 posts | 54 followers
Follow
API Gateway
API Gateway provides you with high-performance and high-availability API hosting services to deploy and release your APIs on Alibaba Cloud products.
Learn More
OpenAPI Explorer
OpenAPI Explorer allows you to call an API through its web interface or WebCLI, and view the entire process.
Learn More
AgentBay
Multimodal cloud-based operating environment and expert agent platform, supporting automation and remote control across browsers, desktops, mobile devices, and code.
Learn More
Microservices Engine (MSE)
MSE provides a fully managed registration and configuration center, and gateway and microservices governance capabilities.
Learn MoreMore Posts by Alibaba Cloud Native Community