Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
APPLIES TO: Developer | Basic | Basic v2 | Standard | Standard v2 | Premium | Premium v2
With API Management’s WebSocket API solution, API publishers can quickly add a WebSocket API in API Management via the Azure portal, Azure CLI, Azure PowerShell, and other Azure tools.
WebSocket APIs can be secured by applying API Management's access control policies to the initial handshake operation. You can also test WebSocket APIs using the API test consoles in both Azure portal and developer portal. Building on existing observability capabilities, API Management provides metrics and logs for monitoring and troubleshooting WebSocket APIs.
In this article, you will:
API Management supports WebSocket passthrough.
During the WebSocket passthrough, the client application establishes a WebSocket connection with the API Management gateway, which then establishes a connection with the corresponding backend services. API Management then proxies WebSocket client-server messages.
Note
The client-side and backend-side connections consist of one-to-one mapping.
Per the WebSocket protocol, when a client application tries to establish a WebSocket connection with a backend service, it first sends an opening handshake request. Each WebSocket API in API Management has an onHandshake operation. onHandshake is an immutable, unremovable, automatically created system operation. The onHandshake operation enables API publishers to intercept these handshake requests and apply API Management policies to them.
In the left menu, select APIs > + Add API.
Under Define a new API, select WebSocket.
In the dialog box, select Full and complete the required form fields.
Field | Description |
---|---|
Display name | The name by which your WebSocket API is displayed. |
Name | Raw name of the WebSocket API. Automatically populates as you type the display name. |
WebSocket URL | The base URL with your websocket name. For example: ws://example.com/your-socket-name |
URL scheme | Accept the default |
API URL suffix | Add a URL suffix to identify this specific API in this API Management instance. It has to be unique in this API Management instance. |
Products | Associate your WebSocket API with a product to publish it. |
Gateways | Associate your WebSocket API with existing gateways. |
Click Create.
Navigate to your WebSocket API.
Within your WebSocket API, select the onHandshake operation.
Select the Test tab to access the Test console.
Optionally, provide query string parameters required for the WebSocket handshake.
Click Connect.
View connection status in Output.
Enter value in Payload.
Click Send.
View received messages in Output.
Repeat preceding steps to test different payloads.
When testing is complete, select Disconnect.
Use standard API Management and Azure Monitor features to monitor WebSocket APIs:
For example, the following screenshot shows recent WebSocket API responses with code 101
from the ApiManagementGatewayLogs table. These results indicate the successful switch of the requests from TCP to the WebSocket protocol.
The following are the current restrictions of WebSocket support in API Management:
Host
headers, in onHandshake requests.For WebSocket connection limits, see API Management limits.
The following policies aren't supported by and can't be applied to the onHandshake operation:
Note
If you applied the policies at higher scopes (for example, global or product) and they're inherited by a WebSocket API through the policy, they are skipped at runtime.
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Aprenda a agregar una aplicación de API web habilitada para OpenAPI a Azure API Management mediante Visual Studio.
Certification
Microsoft Certified: Azure Cosmos DB Developer Specialty - Certifications
Escribe consultas eficaces, crea directivas de indexación, administra y aprovisiona recursos en la API de SQL y el SDK con Microsoft Azure Cosmos DB.