Skip to main content
snipp-gg/snipp-rust
crates.io/crates/snipp

Installation

Add to your Cargo.toml:

Getting Started

Regional endpoints

Use with_region to pin the client to a specific regional host. Uploads run at the same speed either way; this controls which region stores your files.

Methods

All methods are async and return Result<T, SnippError>. Responses deserialize into typed structs (Post, PostFile, User, PostList, and the rest) that follow the shapes in the API reference. Fields are Option only where the API can send null or leave them out.

get_user(id)

Fetch a user by ID. Pass "@me" for the authenticated user. api_key, key_has_uploads_access, upload_count, and limits are only Some on yourself.

get_user_posts(id, options)

List a user’s public posts, newest first. Team, private, unlisted, moderated, and restricted posts are never included. Pass "@me" for your own public posts. ListOptions takes limit (1 to 100, default 30) and cursor (the next_cursor from the previous page).

list_posts(options)

List your own posts of every privacy, newest first. Team posts are not included. Takes the same ListOptions as get_user_posts. Follow next_cursor until it is None to walk every page.

get_post(code)

Fetch a post by its share code. Team posts are only readable by members of that team, and have like_count and liked set to None.

upload(path, options)

Upload a file from disk as a new post. UploadOptions takes privacy (defaults to private when omitted), title (max 30 chars), description (max 200 chars), post_type (sent as the post-type header; it has no effect through upload(), which sends a single file, so use add_files to build an album), include_metadata (keep the file’s metadata such as EXIF and location, which the server strips when None), and priority (priority adaptive streaming for videos; None lets the server enable it when your plan is eligible). Returns url (the direct file URL) and post, whose url is the share page, https://snipp.gg/p/{code} or https://{domain}/{code} on your link domain.

update_post(code, options)

Update a post’s title, description, or privacy. Only the UpdatePostOptions fields that are Some are changed; empty strings clear the title or description. A team post’s privacy cannot be changed. Returns post.

add_files(code, file_paths, options)

Add one or more files to an existing post, turning it into an album. The post’s share code, privacy, title, and description are preserved. Posts cap at 50 files total. Requests that would exceed the cap are rejected. New files inherit the post’s privacy. AddFilesOptions takes include_metadata and priority, which work as on upload(). Returns post, plus failed when some files were rejected, each with its index and error.

delete_file(code, name)

Delete one file from a post, by the name it has in post.files. Deleting a post’s only file deletes the post.

delete_post(code)

Delete a post and every file in it.

report_post(code, reason)

Report a post, with an optional reason (max 200 chars).

report_user(id, reason)

Report a user, with an optional reason (max 200 chars).

Error Handling

All errors are returned as SnippError, which covers API errors, HTTP errors, local input validation, deserialization failures, and IO errors. SnippError::Api carries:

Migrating from 2.x

3.0 follows the reorganized Snipp API.
  • Response structs now match the API: fields the API always sends are plain values instead of Option, and Option is kept only where a value can be null or absent.
  • GetPostResponse, UploadsResponse, EditUploadResponse, and AppendUploadResponse are replaced by PostResponse, PostList, and AddFilesResponse, all built on one Post struct: privacy (was post_privacy), created_at (was created), view_count (was views), files[].name (was file_name), and file_count replaces is_album.
  • UploadResponse is { url, post }; message, file, and processing_time are gone.
  • User carries plan (Plan::Free, Plus, or Ultra) in place of plus, ultra, and badges, created_at in place of created, and blocking in place of blocked_by_you.
  • The API now sends every error as an error object with type, message, and any context fields. SnippError::Api gains kind, message falls back to the HTTP status text instead of the raw response body, and context fields moved from the top of body into body["error"]. A check on body["suspended"] becomes kind.as_deref() == Some("suspended").