| Crates.io | hackmd-api-client-rs |
| lib.rs | hackmd-api-client-rs |
| version | 0.2.0 |
| created_at | 2025-05-23 19:58:38.264922+00 |
| updated_at | 2025-05-26 10:52:23.828469+00 |
| description | 🦀📝 A HackMD Rust API client for rustacean & friends |
| homepage | https://docs.rs/hackmd-api-client-rs |
| repository | https://github.com/EastSun5566/hackmd-api-client-rs |
| max_upload_size | |
| id | 1686667 |
| size | 88,194 |
🦀📝 A Rust client library for the HackMD API.
You can sign up for an account at hackmd.io, and then create access tokens by following the developer portal.
tokiocargo add hackmd-api-client-rs
use hackmd_api_client_rs::{ApiClient, ApiClientOptions};
use hackmd_api_client_rs::types::CreateNoteOptions;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create API client
let client = ApiClient::new(
"<YOUR_ACCESS_TOKEN>",
None, // Use default API endpoint
Some(ApiClientOptions::default()),
)?;
// Get user information
let user = client.get_me().await?;
println!("User: {} ({})", user.name, user.email.unwrap_or_default());
// Create a new note
let note_options = CreateNoteOptions {
title: Some("My First Note".to_string()),
content: Some("# Hello World\\n\\nThis is my first note!".to_string()),
read_permission: None,
write_permission: None,
comment_permission: None,
permalink: None,
};
let note = client.create_note(¬e_options).await?;
println!("Created note: {} (ID: {})", note.note.title, note.note.id);
Ok(())
}
You can customize the client behavior with ApiClientOptions:
use hackmd_api_client_rs::{ApiClient, ApiClientOptions, RetryOptions};
use std::time::Duration;
let options = ApiClientOptions {
wrap_response_errors: true, // Convert HTTP errors to custom error types
timeout: Some(Duration::from_secs(30)), // Request timeout
retry_options: Some(RetryOptions {
max_retries: 3,
base_delay: Duration::from_millis(100),
}),
};
let client = ApiClient::new("<YOUR_ACCESS_TOKEN>", None, Some(options))?;
get_me() - Get current user informationget_history() - Get user's note historyget_note_list() - Get user's notesget_note(note_id) - Get a specific notecreate_note(options) - Create a new noteupdate_note(note_id, options) - Update a noteupdate_note_content(note_id, content) - Update note content onlydelete_note(note_id) - Delete a noteget_teams() - Get user's teamsget_team_notes(team_path) - Get team's notescreate_team_note(team_path, options) - Create a team noteupdate_team_note(team_path, note_id, options) - Update a team noteupdate_team_note_content(team_path, note_id, content) - Update team note contentdelete_team_note(team_path, note_id) - Delete a team noteThe client provides comprehensive error handling with custom error types:
use hackmd_api_client_rs::error::ApiError;
match client.get_me().await {
Ok(user) => println!("User: {}", user.name),
Err(ApiError::TooManyRequests(err)) => {
println!("Rate limited: {}/{} requests remaining",
err.user_remaining, err.user_limit);
},
Err(ApiError::InternalServer(err)) => {
println!("Server error: {}", err.message);
},
Err(err) => println!("Other error: {}", err),
}
Run the basic usage example:
cargo run --example basic_usage
[!NOTE] Make sure to set your HackMD access token in the example code before running.
advanced usage example:
cargo run --example advanced_usage
All API types are available in the types module:
User - User informationTeam - Team informationNote - Note metadataSingleNote - Note with contentCreateNoteOptions - Options for creating notesUpdateNoteOptions - Options for updating notesMIT License