corrected response mapping from API requests
This commit is contained in:
parent
b495fd6924
commit
2e90e6fa39
@ -7,8 +7,8 @@ let api_url = "http://localhost:8989";
|
|||||||
print("Getting node information:");
|
print("Getting node information:");
|
||||||
try {
|
try {
|
||||||
let node_info = mycelium_get_node_info(api_url);
|
let node_info = mycelium_get_node_info(api_url);
|
||||||
print(`Node subnet: ${node_info.subnet}`);
|
print(`Node subnet: ${node_info.nodeSubnet}`);
|
||||||
print(`Node public key: ${node_info.publicKey}`);
|
print(`Node public key: ${node_info.nodePubkey}`);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
print(`Error getting node info: ${err}`);
|
print(`Error getting node info: ${err}`);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
use base64::encode;
|
||||||
|
|
||||||
/// Get information about the Mycelium node
|
/// Get information about the Mycelium node
|
||||||
///
|
///
|
||||||
@ -45,7 +46,7 @@ pub async fn get_node_info(api_url: &str) -> Result<Value, String> {
|
|||||||
/// * `Result<Value, String>` - The list of peers as a JSON value, or an error message
|
/// * `Result<Value, String>` - The list of peers as a JSON value, or an error message
|
||||||
pub async fn list_peers(api_url: &str) -> Result<Value, String> {
|
pub async fn list_peers(api_url: &str) -> Result<Value, String> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let url = format!("{}/api/v1/peers", api_url);
|
let url = format!("{}/api/v1/admin/peers", api_url);
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&url)
|
.get(&url)
|
||||||
@ -78,7 +79,7 @@ pub async fn list_peers(api_url: &str) -> Result<Value, String> {
|
|||||||
/// * `Result<Value, String>` - The result of the operation as a JSON value, or an error message
|
/// * `Result<Value, String>` - The result of the operation as a JSON value, or an error message
|
||||||
pub async fn add_peer(api_url: &str, peer_address: &str) -> Result<Value, String> {
|
pub async fn add_peer(api_url: &str, peer_address: &str) -> Result<Value, String> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let url = format!("{}/api/v1/peers", api_url);
|
let url = format!("{}/api/v1/admin/peers", api_url);
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.post(&url)
|
.post(&url)
|
||||||
@ -114,7 +115,7 @@ pub async fn add_peer(api_url: &str, peer_address: &str) -> Result<Value, String
|
|||||||
/// * `Result<Value, String>` - The result of the operation as a JSON value, or an error message
|
/// * `Result<Value, String>` - The result of the operation as a JSON value, or an error message
|
||||||
pub async fn remove_peer(api_url: &str, peer_id: &str) -> Result<Value, String> {
|
pub async fn remove_peer(api_url: &str, peer_id: &str) -> Result<Value, String> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let url = format!("{}/api/v1/peers/{}", api_url, peer_id);
|
let url = format!("{}/api/v1/admin/peers/{}", api_url, peer_id);
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.delete(&url)
|
.delete(&url)
|
||||||
@ -146,7 +147,7 @@ pub async fn remove_peer(api_url: &str, peer_id: &str) -> Result<Value, String>
|
|||||||
/// * `Result<Value, String>` - The list of selected routes as a JSON value, or an error message
|
/// * `Result<Value, String>` - The list of selected routes as a JSON value, or an error message
|
||||||
pub async fn list_selected_routes(api_url: &str) -> Result<Value, String> {
|
pub async fn list_selected_routes(api_url: &str) -> Result<Value, String> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let url = format!("{}/api/v1/routes/selected", api_url);
|
let url = format!("{}/api/v1/admin/routes/selected", api_url);
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&url)
|
.get(&url)
|
||||||
@ -178,7 +179,7 @@ pub async fn list_selected_routes(api_url: &str) -> Result<Value, String> {
|
|||||||
/// * `Result<Value, String>` - The list of fallback routes as a JSON value, or an error message
|
/// * `Result<Value, String>` - The list of fallback routes as a JSON value, or an error message
|
||||||
pub async fn list_fallback_routes(api_url: &str) -> Result<Value, String> {
|
pub async fn list_fallback_routes(api_url: &str) -> Result<Value, String> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let url = format!("{}/api/v1/routes/fallback", api_url);
|
let url = format!("{}/api/v1/admin/routes/fallback", api_url);
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&url)
|
.get(&url)
|
||||||
@ -257,11 +258,11 @@ pub async fn send_message(api_url: &str, destination: &str, topic: &str, message
|
|||||||
/// * `Result<Value, String>` - The received messages as a JSON value, or an error message
|
/// * `Result<Value, String>` - The received messages as a JSON value, or an error message
|
||||||
pub async fn receive_messages(api_url: &str, topic: &str, count: u32) -> Result<Value, String> {
|
pub async fn receive_messages(api_url: &str, topic: &str, count: u32) -> Result<Value, String> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let url = format!("{}/api/v1/messages/{}", api_url, topic);
|
let url = format!("{}/api/v1/messages", api_url);
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&url)
|
.get(&url)
|
||||||
.query(&[("count", count)])
|
.query(&[("topic", encode(topic)), ("count", count.to_string())])
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Failed to send request: {}", e))?;
|
.map_err(|e| format!("Failed to send request: {}", e))?;
|
||||||
|
Loading…
Reference in New Issue
Block a user