Skip to main content

WebSocket API

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.

Note:

  • 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.

Note:

  • 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.

adada

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.

adada

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.

adada

Note:

  • 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/

adada

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.

adada

FAQ

  • Why is there no response validation?

When a WebSocket request establishes a connection, the HTTP status code is typically 101, indicating that the protocol has been upgraded. Therefore, validating the status code is not very meaningful.

  • There is no Auth tab. How can I authenticate the WebSocket API?

Currently, two methods are recommended for WebSocket API authentication:

  1. Pass the authentication information in a field of Param, Header, or Cookie when establishing a connection;
  2. Pass the authentication information in a field of the message when sending a message.
  • Does Apidog's WebSocket support pre/post-scripts and assertions?

    Not yet, but it is already in the design and development phase.

    Does it support request and response examples?

    Not yet, but it will be evaluated for future iterations.

    Why is there no Mock?

    Currently, API definition for WebSocket is not supported, so message bodies cannot be generated based on definitions. It will be evaluated for future iterations.