483bdd592e
* Add LemmyResult to session_middleware tests * Add LemmyResult to inboxes tests * Add LemmyResult to slurs tests * Add LemmyResult to markdown tests * Add LemmyResult to rate_limiter tests * Add LemmyResult to error tests * Add LemmyResult to api_common utils tests * Add LemmyResult to request tests * Add LemmyResult to claims tests * Propagate registration_applications errors * Remove clippy::unwrap_used from community tests * Add LemmyResult to community_view tests * Add LemmyResult to db_schema post tests * Add LemmyResult to site_aggregates tests * Add LemmyResult to private_message tests * Add LemmyResult to activity tests * Add LemmyResult to federation_allowlist tests * Add LemmyResult to comment_aggregates tests * Add LemmyResult to post_report tests * Add LemmyResult to moderator tests * Add LemmyResult to community_aggregates tests * Add LemmyResult to person_aggregates tests * Add LemmyResult to language tests * Add LemmyResult to post_aggregates tests * Add LemmyResult to db_schema comment tests * Add LemmyResult to actor_language tests * Add LemmyResult to vote_view tests * Add LemmyResult to registration_application_view tests * Add LemmyResult to private_message_view tests * Add LemmyResult to private_message_report_view tests * Add LemmyResult to post_report_view tests * Add LemmyResult to comment_report_view tests * Add LemmyResult to sitemap tests * Replace .expect() with .unwrap() * Format code * Remove clippy::unwrap_used from activity tests * Add diesel result in db_schema tests * Format code * Map to_bytes() error to LemmyErrorType * Remove clippy::unwrap_used from error tests * Removing a few more unwraps, and cleaning up language code. * Replace map_err with unwrap_or_default * Replace ok_or with and_then --------- Co-authored-by: Dessalines <tyhou13@gmx.com> |
||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
README.md |
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/v3/post/list")
.query(¶ms)
.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.