basic_usage/
basic_usage.rs1use hackmd_api_client_rs::{ApiClient, CreateNoteOptions};
2
3#[tokio::main]
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let client = ApiClient::new("your_access_token_here")?;
7
8 match client.get_me().await {
10 Ok(user) => {
11 println!("User: {} ({})", user.name, user.email.unwrap_or_default());
12 println!("User path: {}", user.user_path);
13 println!("Teams: {}", user.teams.len());
14 }
15 Err(e) => {
16 eprintln!("Error getting user info: {}", e);
17 }
18 }
19
20 let note_options = CreateNoteOptions {
22 title: Some("Test Note from Rust".to_string()),
23 content: Some(
24 "# Hello from Rust\n\nThis note was created using the Rust HackMD API client."
25 .to_string(),
26 ),
27 read_permission: None,
28 write_permission: None,
29 comment_permission: None,
30 permalink: None,
31 };
32
33 match client.create_note(¬e_options).await {
34 Ok(note) => {
35 println!("Created note: {} (ID: {})", note.note.title, note.note.id);
36
37 let updated_content = "# Updated from Rust\n\nThis content has been updated!";
39 match client
40 .update_note_content(¬e.note.id, updated_content)
41 .await
42 {
43 Ok(_) => println!("Note content updated successfully"),
44 Err(e) => eprintln!("Error updating note: {}", e),
45 }
46 }
47 Err(e) => {
48 eprintln!("Error creating note: {}", e);
49 }
50 }
51
52 match client.get_note_list().await {
54 Ok(notes) => {
55 println!("Found {} notes", notes.len());
56 for note in notes.iter().take(5) {
57 println!(" - {} ({})", note.title, note.id);
58 }
59 }
60 Err(e) => {
61 eprintln!("Error getting notes: {}", e);
62 }
63 }
64
65 Ok(())
66}