Server functions are an ergonomic way to call a function on the server. Server function work by registering an endpoint on the server and using requests on the client. Most of the time, you shouldn't need to worry about how server functions operate, but there are some times when you need to get some value from the request other than the data passed in the server function.

For example, requests contain information about the user's browser (called the user agent). We can use an extractor to retrieve that information.

You can use the extract method within a server function to extract something from the request. You can extract any type that implements FromServerContext (or when axum is enabled, you can use axum extractors directly):

pub async fn log_user_agent() -> Result<(), ServerFnError> {
    let axum::TypedHeader(user_agent): axum::TypedHeader<axum::headers::UserAgent> = extract().await?;
    log::info!("{:?}", user_agent);