First project code review

I'd like to get a code review for my first project.
Please, feel free to discuss any aspect of it.

(commit history is missing, since it was developed in a closed repository prior to this)


type_matrux allows you to search and query data on Drukarnia website. Although it's not currently implemented, there's a plan to make it also possible to authorize on a website, and perform any operation one would do with on the actual website (post articles and comments, and interact with other users). I aimed for the most accurate fetched data representation, so that there would be no surprises, like missing/redundant fields, or unexpected field format. To test for that, there are "reinforcement tests" in the test suite - these attempt to deserialize a large returned data amount to prove that it's representation is indeed correct.

I would not recommend creating a separate method for each endpoint/request. That's not extensible and requires a lot of boilerplate (as evidenced by e.g. your json_ok!() macro), making the code hostile to refactoring.

I instead suggest you follow how I usually wrap HTTP APIs. The TL;DR is:

  • Represent requests and responses using types

  • Make these types implement common Request and Response traits that allow you to convert between strong, Rust-native types and weak, HTTP-native types. Hopefully, this should be as easy as adding Serialize/Deserialize as supertrait bouds and deriving the traits for your request/response model types.

  • Request should have the Response as an associated type

  • The client should have exactly one method for sending a request, with the approximate signature of:

    fn send<R>(&self, request: R) -> Result<R::Response, MyApiError>
        R: Request;