vovk_hello_world v0.0.69

A showcase app built with Next.js + Vovk.ts + Zod. For more details, visit https://vovk.dev/hello-world
License: MIT
# Install the package
cargo install vovk_hello_world
mod user_rpc
user_rpc::update_user
Update user
Update user by ID
POST https://hello-world.vovk.dev/api/users/{id}
use vovk_hello_world::user_rpc;
use serde_json::{
from_value,
json
};
#[tokio::main]
async fn main() {
let response = user_rpc::update_user(
from_value(json!({
// -----
// User data object
// -----
// User email
"email": "john@example.com",
// User profile object
"profile": {
// User full name
"name": "John Doe",
// User age
"age": 25
}
})).unwrap(), /* body */
from_value(json!({
// -----
// Query parameters
// -----
// Notification type
"notify": "email"
})).unwrap(), /* query */
from_value(json!({
// -----
// Path parameters
// -----
// User ID
"id": "123e4567-e89b-12d3-a456-426614174000"
})).unwrap(), /* params */
None, /* headers (HashMap) */
None, /* api_root */
false, /* disable_client_validation */
).await;
match response {
Ok(output) => println!("{:?}", output),
/*
output {
// -----
// Response object
// -----
// Success status
success: true,
// User ID
id: "00000000-0000-0000-0000-000000000000",
// Notification type
notify: "email"
}
*/
Err(e) => println!("error: {:?}", e),
}
}
mod stream_rpc
stream_rpc::stream_tokens
Stream tokens
Stream tokens to the client
GET https://hello-world.vovk.dev/api/streams/tokens
use vovk_hello_world::stream_rpc;
use serde_json::{
from_value,
json
};
use futures_util::StreamExt;
#[tokio::main]
async fn main() {
let response = stream_rpc::stream_tokens(
(), /* body */
(), /* query */
(), /* params */
None, /* headers (HashMap) */
None, /* api_root */
false, /* disable_client_validation */
).await;
match response {
Ok(mut stream) => {
let mut i = 0;
while let Some(item) = stream.next().await {
match item {
Ok(value) => {
println!("#{}: {:?}", i, value);
/*
#0: iteration {
// -----
// Streamed token object
// -----
// Message from the token
message: "string"
}
*/
i += 1;
}
Err(e) => {
eprintln!("stream error: {:?}", e);
break;
}
}
}
},
Err(e) => println!("Error initiating stream: {:?}", e),
}
}
mod open_api_rpc
open_api_rpc::get_spec
OpenAPI spec
Get the OpenAPI spec for the “Hello World” app API
GET https://hello-world.vovk.dev/api/static/openapi.json
use vovk_hello_world::open_api_rpc;
use serde_json::{
from_value,
json
};
#[tokio::main]
async fn main() {
let response = open_api_rpc::get_spec(
(), /* body */
(), /* query */
(), /* params */
None, /* headers (HashMap) */
None, /* api_root */
false, /* disable_client_validation */
).await;
}