lemmy/crates/api_common
Dessalines 5fa6a490d5
Create actions structs (#5482)
* migration

* update code

* tests

* triggers

* fix

* fmt

* clippy

* post aggregate migration

* changes for post aggregate code

* wip: update tests for post aggregate

* format

* fix partialeq

* trigger fix

* fix post insert trigger

* wip

* reorder

* fixes

* community aggregate migration

* update code

* triggers

* person aggregate migration

* person aggregate code

* person triggers

* test fixes

* fix scheduled task

* update api tests

* site_aggregates to local_site migration

* site_aggregates code changes

* triggers, tests

* more fixes

* Rename PersonPostAggregates to PostActions

* Merge local_user_vote_display_mode into local_user

* fix schema

* remove duplicate fields

* remove "aggregates" from index names

* uncomment indices

* if count = 0

* remove commentaggregates

* Fix triggers in remove aggregates tables pr (#5451)

* prevent all db_schema test errors

* fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows

* remove unnecessary recursion checks and add comment to remaining check

* clean up

* Fixing SQL format.

* Update triggers.sql

* Update triggers.sql

* Update triggers.sql

* Update triggers.sql

* remove update of deleted column

---------

Co-authored-by: Dessalines <tyhou13@gmx.com>

* rename migration

* Fix migration errors

* Move community.hidden to visibility (fixes #5458)

* Fixing person_saved_combined. (#5481)

* Remove comment and post specific action structs. #5473

* Doing reports

* fix up migration by dropping index

* also add enum variant `LocalOnlyPublic`, rename `LocalOnly` to `LocalOnlyPrivate`

fixes #5351

* fix column order in down.sql

* wip

* Moving blocks.

* Adding a few more views.

* more wip

* fixes

* migration for modlog

* fix migration

* Working views and schema.

* Fix ts_optionals.

* wip

* db_schema compiling

* make the code compile

* Merging from main.

* lint

* Fixing SQL format.

* fix down migration

* Fixing api tests.

* Adding field comments for the actions tables.

* Refactoring CommunityFollower to include follow_state

* fix test

* make hidden status federate

* ts attr

* fix

* fix api test

* Update crates/api/src/reports/post_report/resolve.rs

Co-authored-by: Nutomic <me@nutomic.com>

* Addressing PR comments

* Fix ts export.

* update api client

* review

* Extracting filter_not_hidden_or_is_subscribed (#5497)

* Extracting filter_not_hidden_or_is_subscribed

* Cleanup.

* Cleanup 2.

* Remove follower_state_helper function.

* Cleaning up some utils functions.

* rename hidden to unlisted

---------

Co-authored-by: Felix Ableitner <me@nutomic.com>
Co-authored-by: dullbananas <dull.bananas0@gmail.com>
2025-03-12 11:51:34 -04:00
..
src Create actions structs (#5482) 2025-03-12 11:51:34 -04:00
Cargo.toml Use rust:1.81 for CI. (#5423) 2025-02-13 09:51:42 +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.