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

Rust axum guide #6783

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Rust axum guide #6783

wants to merge 7 commits into from

Conversation

Dhghomon
Copy link
Contributor

@Dhghomon Dhghomon commented Feb 6, 2024

No description provided.

@MrFoxPro
Copy link

MrFoxPro commented Feb 6, 2024

Would like to see some good practices for organaizing structs / code / files when there are a bunch of queries that shares similiar shapes and how to organize all structs which describes return types (derived from Queryable).

@Dhghomon
Copy link
Contributor Author

Dhghomon commented Feb 7, 2024

Would like to see some good practices for organaizing structs / code / files when there are a bunch of queries that shares similiar shapes and how to organize all structs which describes return types (derived from Queryable).

Something really comprehensive might turn this from a quick guide into something else but have added two tips off the top of my head that fit with the Open-Meteo output:

1cc57b0

@Dhghomon Dhghomon marked this pull request as ready for review February 7, 2024 02:23
@MrFoxPro
Copy link

Let's say I want to return Json directly without using serde. How can I do it?
How to convert edgedb_protocol::model::Json to axum::Json?

@MrFoxPro
Copy link

MrFoxPro commented Mar 11, 2024

impl IntoResponse for edb_model::Json {
   fn into_response(self) -> axum::response::Response {
      (
         [(
            axum::http::header::CONTENT_TYPE,
            "application/json".parse::<axum::http::HeaderValue>().unwrap(),
         )],
         self.to_string(),
      )
   }
}

only traits defined in the current crate can be implemented for types defined outside of the crate

Something like this can help:

struct EdgedbJson(edb_model::Json);
impl IntoResponse for EdgedbJson {
   fn into_response(self) -> axum::response::Response {
      let mut response = Response::new(self.0.to_string().into());
      response.headers_mut().append(
         axum::http::header::CONTENT_TYPE,
         "application/json".parse::<axum::http::HeaderValue>().unwrap(),
      );
      response
   }
}

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

Successfully merging this pull request may close these issues.

None yet

2 participants