Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The client contributer example for Rust is wrong #254

Open
MarcCoquand opened this issue Jul 19, 2023 · 1 comment
Open

The client contributer example for Rust is wrong #254

MarcCoquand opened this issue Jul 19, 2023 · 1 comment

Comments

@MarcCoquand
Copy link

MarcCoquand commented Jul 19, 2023

Hi!

The example included for contributers is wrong:

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/api/v3/post/list")
        .send_json(&params).unwrap()
        .into_json().unwrap()
}

It's a get request that sends a json body. If users try this example it won't fail, but they will find that changing sort and type does not work. An example that could be included for get requests:

use lemmy_api_common::post::{GetPostsResponse};

pub fn list_posts() -> GetPostsResponse {
    Agent::new()
        .get("https://lemmy.ml/api/v3/post/list")
        .query("sort", "Hot")
        .call()
        .unwrap()
        .into_json()
        .unwrap()
}

This one will work, and users are able to play around with it.

But might be a bit underwhelming as an example for those trying to learn.

@Nutomic
Copy link
Member

Nutomic commented Jul 20, 2023

Maybe its better to use reqwest for the example. Here is the equivalent code, would you make a pull request with that?

https://github.com/LemmyNet/lemmyBB/blob/main/src/api/post.rs#L23

https://github.com/LemmyNet/lemmyBB/blob/main/src/api/mod.rs#L81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants