Function leptos_axum::handle_server_fns_with_context
source · pub async fn handle_server_fns_with_context(
additional_context: impl Fn() + 'static + Clone + Send,
req: Request<Body>
) -> impl IntoResponse
Expand description
An Axum handlers to listens for a request with Leptos server function arguments in the body,
run the server function if found, and return the resulting Response
.
This can then be set up at an appropriate route in your application:
This version allows you to pass in a closure to capture additional data from the layers above leptos and store it in context. To use it, you’ll need to define your own route, and a handler function that takes in the data you’d like. See the render_app_to_stream_with_context docs for an example of one that should work much like this one.
NOTE: If your server functions expect a context, make sure to provide it both in
handle_server_fns_with_context
and in
leptos_routes_with_context
(or whatever
rendering method you are using). During SSR, server functions are called by the rendering
method, while subsequent calls from the client are handled by the server function handler.
The same context needs to be provided to both handlers.
§Provided Context Types
This function always provides context values including the following types: