Type Definition warpgrapher::engine::events::BeforeRequestFunc
source · [−]pub type BeforeRequestFunc<R> = fn(_: R, _: EventFacade<'_, R>, _: HashMap<String, String>) -> BoxFuture<'_, Result<R, Error>>;
Expand description
Type alias for a function called before request execution allowing modifications to the request context. Common use case includes pulling auth tokens from the metadata and inserting user information into the request context.
Examples
type Rctx = ();
fn before_request(
mut rctx: Rctx,
mut ef: EventFacade<Rctx>,
metadata: HashMap<String, String>
) -> BoxFuture<Result<Rctx, warpgrapher::Error>> {
Box::pin(async move {
// modify request context
Ok(rctx)
})
}