Skip to content

How does axum actually wire routes and handlers? #1438

Answered by davidpdrsn
nihalpasham asked this question in Q&A
Discussion options

You must be logged in to vote

Great question!

I'm gonna talk about how it works in 0.6, things work similarly in 0.5.

  • Router::route takes a path and a MethodRouter.
  • The MethodRouter is is constructed via something like axum::routing::get.
  • get, post, etc are all the same so they're defined in a macro here.
  • That calls axum::routing::on which calls MethodRouter::on
  • That calls MethodRouter::on_service but requires a service. Previously we've only received a H: Handler<T, S, B>. How the Handler trait works is a different question and somewhat orthogonal.
  • So we convert the Handler into a Service with IntoServiceStateInExtension. That is why you never see Handler::call being called. Because we call it via IntoServiceStateIn…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@nihalpasham
Comment options

@davidpdrsn
Comment options

@nihalpasham
Comment options

@davidpdrsn
Comment options

@nihalpasham
Comment options

Answer selected by nihalpasham
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants