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.
onHandshake operationPer 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.
Add a WebSocket API
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.
Limitations
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.
Unsupported policiesThe 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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4