lemmy/crates/api_common
Nutomic a91a03a536
Image api rework (#5260)
* Split image endpoints into API v3 and v4

* Move into subfolders

* Upload avatar endpoint and other changes

* Various other changes

fixes #1772
fixes #4001

* clippy

* config options

* fix ts bindings

* fix api tests

* Add option to disable image upload (fixes #1118)

* split files into upload, download

* move sitemap to top level, not in api

* simplify code

* add upload user banner

* community icon/banner

* site icon/banner

* update js client

* wip

* add delete endpoints

* change comment

* optimization

Co-authored-by: dullbananas <dull.bananas0@gmail.com>

* move fn

* 1024px banner

* dont use static client

* fix api tests

* shear

* proxy pictrs in request.rs (fixes #5270)

* clippy

* try to fix api tests

* skip api tests

* create user

* debug

* dbg

* test

* image

* run another

* fixed?

* clippy

* fix

* fix health check

---------

Co-authored-by: dullbananas <dull.bananas0@gmail.com>
2025-01-13 16:09:00 -05:00
..
src Image api rework (#5260) 2025-01-13 16:09:00 -05:00
Cargo.toml Running cargo-features-manager prune. (#5274) 2024-12-20 23:20:16 +01:00
README.md Reorganize api endpoints (fixes #2022) (#5216) 2024-12-07 14:06:33 -07:00

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.