Skip to main content

WebSocket

This article is about WebSocket API management in Apidog.

WebSocket is an API technology that enables full-duplex communication over a single TCP connection. Compared to traditional HTTP requests, WebSocket has lower latency and higher efficiency. It is suitable for scenarios that require long-term connections and real-time data transmission, such as online games, real-time chats, and more.

tip
  • WebSocket API management is only supported by Apidog versions equal to or greater than 2.2.34.

Creating a WebSocket API

You can create a WebSocket API in an HTTP project.

  1. Click the + button on the left and select New WebSocket API (Beta).
  2. Enter the URL of the WebSocket server, starting with ws or wss.
  3. Click Connect.
  4. To disconnect the WebSocket API, click Disconnect.
tip
  • We recommend using the Apidog client to use the full features and the best experience of the WebSocket API.

Sending Messages

After establishing a WebSocket connection, you can compose messages under the Message tab.

In addition to directly composing messages in text formats such as Text, JSON, XML, HTML, you can also compose messages in binary formats using Base64 or Hexadecimal.

The editor will syntax highlight the message content based on the selected message format. If the message is in JSON, XML, or HTML format, you can also format the input content.

Viewing Message

The Messages below show the connection status, sent messages, and received messages in chronological order.

Click a single message to view the message details on the right:

  • If the message is in the text format, the formatted message will be displayed by default, and you can manaully switch the messsage format and encoding.

  • If the message is in binary format, the message's Hexdump will be displayed by default, and you can also view the message encodeed with Base64 and the original message.

Adding Handshake Request Parameters

You can also customize the parameters required to pass during WebSocket handshake, such as Params,Headers,Cookies to meet authentication or other complex scenarios.

tip

The handshake request parameters cannot be modified after the connection is established and must be configured before the connection is established or after the connection is disconnected.

Using Variables

You can use Apidog variables in the WebSocket connection's handshake and messages. For more information on using variables,check on https://apidog.com/help/api-manage/variables/

API Documentation

You can set the status, responsible person, and tags for the WebSocket API, and write a detailed API description in Markdown format.

Of course, you can share the WebSocket API document with teams outside and view it directly in the browser.

Save API

After debugging is complete, you can click the Save button to save the WebSocket API to the directory tree of the HTTP project, so that other members of the team can debug or view the API documentation.

FAQ

You can check the FAQ:Websocket if you encounter problems when exporting data.