Skip to content

Should I create a Service, Layer, Handler, or Extractor for a slack verification "middleware" #625

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

You must be logged in to vote

Sounds to me like you want a Service (a middleware) that grabs some headers, buffers the request body, and checks that they match something. You can do that along the lines of:

use axum::{
    body::{Body, BoxBody, Bytes},
    http::{HeaderValue, Request, Response, StatusCode},
    response::IntoResponse,
    routing::get,
    Router,
};
use std::{convert::Infallible, future::Future, net::SocketAddr, pin::Pin};
use tower::{Service, ServiceBuilder};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(|| async { "hi!" }))
        .layer(ServiceBuilder::new().layer_fn(|inner| RequestVerifier { inner }));

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@noxasaxon
Comment options

Answer selected by noxasaxon
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