Questions tagged [rust-axum]
80 questions
2
votes
2 answers
How to conditionally add routes to Axum Router?
I'm using axum and this code to create a server but I get an error:
use axum::{response::Html, routing::get, Router};
async fn handler() -> Html<&'static str> {
Html("
Hello, World!
") } #[tokio::main] async fn main() { let router =…
Fred Hors
- 3,258
- 3
- 25
- 71
2
votes
2 answers
Is there a way to bind a variable to a request in tower-http / hyper / axum?
I'm trying to add a request id to each tracing event. I can do it with tower_http::trace like this:
#[derive(Clone)]
pub struct RequestSpan;
impl tower_http::trace::MakeSpan for RequestSpan {
fn make_span(&mut self, request:…

imbolc
- 1,620
- 1
- 19
- 32
1
vote
2 answers
How can I avoid duplication when I implement a trait for few similar types in Rust
I need to implement the axum::IntoResponse trait for serde structures because they come from another crate:
struct BucketInfoListAxum(BucketList);
impl IntoResponse for BucketInfoListAxum {
fn into_response(self) -> Response {
let mut…

atimin
- 499
- 4
- 11
1
vote
1 answer
leptos with axum: Issue with wasm-bindgen versions
I am just getting started with Rust and Leptos, so I'm also quite new to the whole rust / cargo ecosystem.
I was following the leptos tutorial to setup a new leptos project using axum. When I tried starting the project with
cargo leptos watch
I ran…

platzhersh
- 1,520
- 20
- 35
1
vote
1 answer
Customizing errors from Query extractor in Rust with Axum
I have followed the example provided here to customize the extractor error for the Json extractor:
#[derive(FromRequest)]
#[from_request(via(axum::Json), rejection(ApiError))]
pub struct JsonExtractor(pub T);
#[axum::debug_handler]
pub(crate)…

The Final Cut Cat
- 57
- 1
- 4
1
vote
1 answer
Unable to pass tokio-postgres pool connections to Axum handler
I'm a Rust newbie.
I'm trying to create a pool of tokio-postgres connections to a handler, it should use the connection for fill a database table.
I used deadpool-postgres and it seems it creates the pool.
Problem is that i can't pass the pool to…

bontxa
- 11
- 3
1
vote
1 answer
Protecting an Axum app with OpenID and Zitadel
I try to protect an Axum application by using OpenID and Zitadel. I followed quite closely this quickstart and this authentication flow using PKCE. Everything works fine up until this line:
let claims = id_token.claims(&client.id_token_verifier(),…

Achim
- 15,415
- 15
- 80
- 144
1
vote
0 answers
Error about using axum and tonic together
I'm trying to create a little Grpc-Web Rust server using axum and tonic.
I'm new both to Rust and Grpc.
I managed to generate all the rust code from proto files.
THE REPOSITORY IS HERE: https://github.com/frederikhors/issue-tonic-web
The issue I'm…

Fred Hors
- 3,258
- 3
- 25
- 71
1
vote
0 answers
Failed to deserialize form body: invalid type: sequence, expected a string when trying to deserialize web form with Rust and Axum
I'm trying to build a simple webapp that calculates the determinant of a matrix using Rust and the Axum web framework. My current frontend implementation is a simple HTML web page with a form that firsts asks for the number of rows the matrix has,…

AChenet
- 11
- 1
- 2
1
vote
0 answers
Axum pass value from middleware to route
Not sure I understand why, but I've got a route and a piece of middleware that are arranged like so:
let app = Router::new()
.route("/a-path", post(create_a_thing))
.router_layer(middleware::from_fn(get_auth))
// ...
The middleware…

neezer
- 19,720
- 33
- 121
- 220
1
vote
1 answer
How to pass optional parametr to middleware in from_fn func in axum?
In my axum backend I want to be able to determine what my auth middleware will add to the request: user_id or user model itself. How can I pass the optional full_user parameter to router?
Example of using middleware:
.route("/",…

Azashiro Merume
- 13
- 3
1
vote
0 answers
the trait `async_graphql::OutputType` is not implemented for `entity::user::Model`
i'm trying to return user model in my graphql mutation after it, when i'm making ->ResultUser::Model rust giving an error that the trait 'async_graphql::OutputType' is not implemented for 'entity::user::Model',
i was checking few examples (seaorm…

M1nybe
- 37
- 4
1
vote
2 answers
What is the optimal way to make external network requests using Axum, Tokio, and Hyper in Rust?
I have written pretty basic rust server which makes http call to defined url in environment variable, parse json response and return.
Source Code
| Flamegraph - IO Call
| Dockerfile
| Flamegraph - Static Json
Nginx request - throughput ~30000…

pratik
- 178
- 11
1
vote
1 answer
Rust Axum Get Full URI request
Trying to get the full request URI (scheme + authority + path)
I have found the discussion: https://github.com/tokio-rs/axum/discussions/1149 which says that Request.uri() should have it.
So I tried the following:
use axum::body::Body;
use…

mepmerp
- 701
- 1
- 9
- 16
1
vote
1 answer
How to handle the situation of multiple json parsed for the same route?
I have a requirement that I need to handle a request with multiple ways in a same HTTP route, according to the JSON in the body.
There is a total different JSON object in route root("/")
like
url_verification
{
"challenge":…

Dowson Jones
- 45
- 5