Skip to content

Access body in Middleware #1864

Answered by MartinMinkov
Alacho2 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey! This example shows the way of accessing the body in middleware: https://github.com/tokio-rs/axum/blob/main/examples/consume-body-in-extractor-or-middleware/src/main.rs

It depends on what you would like to do, but in this case, you define your from_request function to do whatever sort of middleware actions you want (e.g. return a custom extractor or validate.

I'm not sure if linking to youtube is encouraged on these issues but I found this tutorial video very helpful in setting up my middleware: https://www.youtube.com/watch?v=5KOr_ATiuAU

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by davidpdrsn
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
Converted from issue

This discussion was converted from issue #1863 on March 19, 2023 18:54.