Skip to content

Commit

Permalink
🎨 Allowing without parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
iota9star committed Dec 20, 2023
1 parent c2e667a commit a731d8b
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,39 @@ async fn handle_get(
Path(method): Path<String>,
Query(query): Query<Value>,
) -> Result<R, AppError> {
let x = query.get("params").unwrap().as_str().unwrap();
let params = serde_json::from_str(x).unwrap();
let r = handle_request(method, params, callbacks, ws_tx).await;
let r = match query.get("params") {
None => handle_request(method, vec![], callbacks, ws_tx).await,
Some(v) => {
let x = v.as_str().map(|s| if s.is_empty() {
"[]"
} else {
s
}).unwrap();
let params = serde_json::from_str(x).unwrap();
handle_request(method, params, callbacks, ws_tx).await
}
};
Ok(r)
}

async fn handle_post(
Extension(callbacks): Extension<Callbacks>,
Extension(ws_tx): Extension<mpsc::UnboundedSender<Message>>,
Path(method): Path<String>,
Json(body): Json<Value>,
body: Option<Json<Value>>,
) -> Result<R, AppError> {
let x = body.get("params").unwrap().as_array().unwrap();
let r = handle_request(method, x.clone(), callbacks, ws_tx).await;
let r = match body {
None => handle_request(method, vec![], callbacks, ws_tx).await,
Some(v) => {
match v.0.get("params") {
None => handle_request(method, vec![], callbacks, ws_tx).await,
Some(v) => {
let x = v.as_array().unwrap();
handle_request(method, x.clone(), callbacks, ws_tx).await
}
}
}
};
Ok(r)
}

Expand Down

0 comments on commit a731d8b

Please sign in to comment.