WebSockets in the Fern Definition
WebSockets enable a user to create a connection with a server, over which bidirectional communication can be sent.
In Fern, you can specify WebSockets in your API definition. The WebSockets will be included in both the generated SDKs and the API documentation.
WebSocket definition
Each WebSocket is defined in its own file, where it is described by the channel
object.
The channel object
A channel
is defined by the following fields:
auth
: The authentication scheme for the WebSocketpath
: The path of the WebSocketheaders
(Optional): Any headers the WebSocket will sendpath-parameters
(Optional): Any path parameters in the WebSocket pathquery-parameters
(Optional): Any query parameters used in the initial request of the WebSocketmessages
(Optional): The schemas of the messages the WebSocket can send and receive once connectedorigin
: The entity that sent the message (e.g.client
orserver
)body
: The schema of the message
examples
: Example WebSocket connection (Optional)
WebSocket example
WebSocket API Reference
WebSocket Reference
Fern renders a unique reference page for WebSockets. The Handshake section outlines the protocol for connecting with the server, while the Send and Receive sections outline the message schemas that can be sent between the client and server.
WebSocket Playground
Users can connect to and use WebSockets from right within the API Reference (check one of Hume’s WebSockets here).