Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to describe WebSocket interface?

For restful services Swagger is a standardized way to describe the interface. Is there already a way to describe Websocket interfaces?

like image 353
JohnDoe Avatar asked Apr 17 '16 08:04

JohnDoe


People also ask

What is WebSocket interface?

The WebSocket API is an advanced technology that makes it possible to open a two-way interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

How do I read WebSocket data?

First, you need to copy your web browser's header to here and use json. dumps to convert it into the string format. After that, create the connection to the server by using create_connection . Then, perform the handshake by sending the message, and you will be able to see the data on your side.

What is WebSocket API and how it works?

The WebSocket API invokes your backend based on the content of the messages it receives from client apps. Unlike a REST API, which receives and responds to requests, a WebSocket API supports two-way communication between client apps and your backend. The backend can send callback messages to connected clients.

How do you write a WebSocket?

A simple example. To open a websocket connection, we need to create new WebSocket using the special protocol ws in the url: let socket = new WebSocket("ws://javascript.info"); There's also encrypted wss:// protocol.

Is WebSockets UDP or TCP?

WebSocket, on the other hand, is an application layer protocol that facilitates bidirectional client-server communication over a single, persistent TCP socket connection.

What is the difference between WS and WSS?

The wss protocol establishes a WebSocket over an encrypted TLS connection, while the ws protocol uses an unencrypted connection. At this point, the network connection remains open and can be used to send WebSocket messages in either direction.


2 Answers

Not at the moment. You may want to join the following discussion about supporting Websocket in the next version of OpenAPI/Swagger spec:

https://github.com/OAI/OpenAPI-Specification/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+Websocket

like image 145
William Cheng Avatar answered Oct 20 '22 17:10

William Cheng


Possibly ASyncAPI? I haven't tried it myself yet, but:

AsyncAPI provides a specification that allows you to define Message-Driven APIs in a machine-readable format. It’s protocol-agnostic, so you can use it for APIs that work over MQTT, AMQP, WebSockets, STOMP, etc. The spec is very similar to OpenAPI/Swagger so, if you’re familiar with them, AsyncAPI should be easy for you.

like image 41
parsley72 Avatar answered Oct 20 '22 16:10

parsley72