docs: add API documentation for websocket connection
This commit is contained in:
parent
24afa3407e
commit
b51aa94d5f
2 changed files with 14 additions and 5 deletions
|
|
@ -75,7 +75,7 @@ async fn main() {
|
||||||
.routes(routes!(routes::book_instance::create_book_instance))
|
.routes(routes!(routes::book_instance::create_book_instance))
|
||||||
.routes(routes!(routes::owner::get_owner_by_id))
|
.routes(routes!(routes::owner::get_owner_by_id))
|
||||||
.routes(routes!(routes::owner::create_owner))
|
.routes(routes!(routes::owner::create_owner))
|
||||||
.route("/ws", get(routes::websocket::ws_handler))
|
.routes(routes!(routes::websocket::ws_handler))
|
||||||
.route("/", get(index))
|
.route("/", get(index))
|
||||||
.with_state(shared_state)
|
.with_state(shared_state)
|
||||||
.split_for_parts();
|
.split_for_parts();
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,29 @@
|
||||||
use std::{net::SocketAddr, ops::ControlFlow, sync::Arc};
|
use std::{net::SocketAddr, ops::ControlFlow, sync::Arc};
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
body::Bytes,
|
body::Bytes, extract::{
|
||||||
extract::{
|
|
||||||
ws::{Message, Utf8Bytes, WebSocket, WebSocketUpgrade},
|
ws::{Message, Utf8Bytes, WebSocket, WebSocketUpgrade},
|
||||||
ConnectInfo,
|
ConnectInfo,
|
||||||
State
|
State
|
||||||
},
|
}, http, response::IntoResponse
|
||||||
response::IntoResponse
|
|
||||||
};
|
};
|
||||||
|
use reqwest::StatusCode;
|
||||||
|
|
||||||
use crate::{utils::events, AppState};
|
use crate::{utils::events, AppState};
|
||||||
|
|
||||||
use futures_util::{sink::SinkExt, stream::StreamExt};
|
use futures_util::{sink::SinkExt, stream::StreamExt};
|
||||||
|
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/ws",
|
||||||
|
responses(
|
||||||
|
(status = SWITCHING_PROTOCOLS, description = "Succesfully reached the websocket, now upgrade to establish the connection"),
|
||||||
|
),
|
||||||
|
summary = "Connect to the websocket",
|
||||||
|
description = "Initial connection to the websocket before upgrading protocols",
|
||||||
|
tag = "websocket",
|
||||||
|
)]
|
||||||
pub async fn ws_handler(
|
pub async fn ws_handler(
|
||||||
ws: WebSocketUpgrade,
|
ws: WebSocketUpgrade,
|
||||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||||
|
|
|
||||||
Reference in a new issue