156 releases

1.0.0-alpha.3 Mar 24, 2025
0.20.0-alpha.5 Feb 4, 2025
0.19.18 Apr 20, 2026
0.19.18-beta.0 Mar 26, 2026
0.11.3-rc.5 Jul 24, 2021

#1129 in Authentication

Download history 23/week @ 2025-12-29 105/week @ 2026-01-05 60/week @ 2026-01-12 74/week @ 2026-01-19 168/week @ 2026-01-26 80/week @ 2026-02-02 73/week @ 2026-02-09 122/week @ 2026-02-16 145/week @ 2026-02-23 199/week @ 2026-03-02 157/week @ 2026-03-09 144/week @ 2026-03-16 111/week @ 2026-03-23 240/week @ 2026-03-30 109/week @ 2026-04-06 134/week @ 2026-04-13

608 downloads per month
Used in 11 crates (10 directly)

AGPL-3.0

2MB
60K SLoC

Rust 30K SLoC // 0.0% comments SQL 29K SLoC // 0.0% comments

lemmy_api_common

This crate provides all the data types which are necessary to build a client for Lemmy. You can use them with the HTTP client of your choice.

Here is an example using reqwest:

    let params = GetPosts {
        community_name: Some("asklemmy".to_string()),
        ..Default::default()
    };
    let client = Client::new();
    let response = client
        .get("https://lemmy.ml/api/v4/post/list")
        .query(&params)
        .send()
        .await?;
    let json = response.json::<GetPostsResponse>().await.unwrap();
    print!("{:?}", &json);

As you can see, each API endpoint needs a parameter type ( GetPosts), path (/post/list) and response type (GetPostsResponse). You can find the paths and handler methods from this file. The parameter type and response type are defined on each handler method.

For a real example of a Lemmy API client, look at lemmyBB.

Lemmy also provides a websocket API. You can find the full websocket code in this file.

Generate TypeScript bindings

TypeScript bindings (API types) can be generated by running cargo test --features full. The ts files be generated into a bindings folder.

This crate uses ts_rs macros derive(TS) and ts(export) to attribute types for binding generating.

Dependencies

~16–43MB
~642K SLoC