HackMD Rust API Client
🦀📝 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.
Features
- ✅ Complete API coverage (User, Notes, Teams, Image Upload)
- ✅ Async/await support with
tokio - ✅ Retry mechanism with exponential backoff
- ✅ Comprehensive error handling & Type-safe request/response
Installation
Set HACKMD_ACCESS_TOKEN before running the examples or your own binaries:
Quick Start
use ;
async
Configuration
You can customize the client behavior with ApiClientOptions:
use ;
use Duration;
let options = ApiClientOptions ;
let access_token = var?;
let client = with_options?;
Use with_base_url() when targeting a self-hosted HackMD deployment. A trailing slash is optional:
let access_token = var?;
let client = with_base_url?;
API Methods
User API
get_me()- Get current user informationget_history(limit)- Get user's note history (limitisOption<u32>)get_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 noteupload_note_image(note_id, image_bytes, file_name, mime_type)- Upload an image for a note
Team API
get_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 note
Error Handling
The client provides comprehensive error handling with custom error types:
use ApiError;
match client.get_me.await
Examples
The examples read HACKMD_ACCESS_TOKEN from the environment. A .env.example template is included if you prefer to keep a local placeholder file.
Run the basic usage example:
Advanced usage example:
Types
All API types are available in the types module:
User- User informationTeam- Team information (owner_id,visibility, etc.)Note- Note metadata (includesdescription,tags,folder_paths,title_updated_at,tags_updated_at)SingleNote- Note with full contentFolderPath- Folder path entry for note folder organisationSimpleUserProfile- Minimal user profile (used inNote.last_change_user)CreateNoteOptions- Options for creating notes (title, content, description, tags, permissions,parent_folder_id,origin, etc.)UpdateNoteOptions- Options for updating notes (title, content, description, tags, permissions,parent_folder_id)NoteImageUploadResponse- Response from the image upload endpointNotePermissionRole-owner|signed_in|guestNotePublishType-edit|view|slide|bookCommentPermissionType-disabled|forbidden|owners|signed_in_users|everyoneSuggestEditPermissionType-disabled|forbidden|owners|signed_in_usersTeamVisibilityType-public|private
Release