mirror of
https://github.com/LemmyNet/lemmy-docs.git
synced 2024-11-22 04:11:09 +00:00
Add documentation for Rust API
This commit is contained in:
parent
8b9c725eb1
commit
e2ac58dfd2
2 changed files with 38 additions and 0 deletions
|
@ -21,6 +21,7 @@
|
||||||
- [Lemmy Protocol](federation/lemmy_protocol.md)
|
- [Lemmy Protocol](federation/lemmy_protocol.md)
|
||||||
- [Client Development](client_development/client_development.md)
|
- [Client Development](client_development/client_development.md)
|
||||||
- [HTTP API extras](client_development/http_api_extras.md)
|
- [HTTP API extras](client_development/http_api_extras.md)
|
||||||
|
- [Rust API](client_development/rust_api.md)
|
||||||
- [Creating a Custom Frontend](client_development/custom_frontend.md)
|
- [Creating a Custom Frontend](client_development/custom_frontend.md)
|
||||||
- [Contributing](contributing/contributing.md)
|
- [Contributing](contributing/contributing.md)
|
||||||
- [Docker Development](contributing/docker_development.md)
|
- [Docker Development](contributing/docker_development.md)
|
||||||
|
|
37
src/en/client_development/rust_api.md
Normal file
37
src/en/client_development/rust_api.md
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# Rust API
|
||||||
|
|
||||||
|
If you want to develop a Rust application which interacts with Lemmy, you can directly pull in the relevant API structs. This relies on the exact code used in Lemmy, but with most heavyweight dependencies disabled (like diesel).
|
||||||
|
|
||||||
|
To get started, add the following to your `Cargo.toml`:
|
||||||
|
|
||||||
|
```
|
||||||
|
[dependencies]
|
||||||
|
lemmy_api_common = { git = "https://github.com/LemmyNet/lemmy.git" }
|
||||||
|
```
|
||||||
|
|
||||||
|
Note, at the time of writing, this code is not available on crates.io yet. You can use "0.16.3" from crates.io, but it pulls in many heavy dependencies including diesel. Best use the git dependency for now, or wait for a newer version to become available.
|
||||||
|
|
||||||
|
You can then use the following code to make an API request:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use lemmy_api_common::post::{GetPosts, GetPostsResponse};
|
||||||
|
use lemmy_db_schema::{ListingType, SortType};
|
||||||
|
use ureq::Agent;
|
||||||
|
|
||||||
|
pub fn list_posts() -> GetPostsResponse {
|
||||||
|
let params = GetPosts {
|
||||||
|
type_: Some(ListingType::Local),
|
||||||
|
sort: Some(SortType::New),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
Agent::new()
|
||||||
|
.get("https://lemmy.ml/post/list")
|
||||||
|
.send_json(¶ms).unwrap()
|
||||||
|
.into_json().unwrap()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also look at the following real-world projects as examples:
|
||||||
|
- [lemmyBB](https://github.com/Nutomic/lemmyBB)
|
||||||
|
- [lemmy-stats-crawler](https://yerbamate.ml/LemmyNet/lemmy-stats-crawler)
|
||||||
|
-
|
Loading…
Reference in a new issue