Skip to content

Support for client request context. #3261

Open

Description

@SandPod

Problem to Solve

Currently, there is no built-in way to access client-specific request context throughout the application lifecycle. This makes implementing features that depend on per-request data, such as localization, user preferences, or configurations difficult.

For example, to implement translations, the application needs to determine the appropriate locale for each request. This now needs to be baked into the parameters received by the endpoint method.

Proposal

Make it possible to configure a client context that is reflected in all requests to the server. The context should be possible to update during the client's lifetime.

The context should have support for multiple values.

The framework should be agnostic to the used transport protocol when the context is communicated.

If more advanced contexts are to be supported, using Serverpod Models for these would be beneficial. These already provide great serialization support and would make the contexts typesafe by default.

Use Case

Communicate device language settings, user preferences or other configuration.

Alternatives

N/A

Additional context

This has been brought up several times in discussions:

HTTP
For HTTP requests, the standard way to transfer request contexts is by using X-header fields. If that approached is used, special care might need to be taken into consideration for streams.

Since we automatically manage the WebSocket connection, and the WebSocket connection is the only "HTTP" request for the stream, context information would never be updated if all streams are not closed.

When the context for the client is updated, any open stream should also have its context updated.

How experienced are you with this library?

Expert - Experienced and comfortable with using this library in complex projects

Are you interested in working on a PR for this?

  • I want to work on this

Activity

  1. added
    area: client
    enhancement
    on Feb 24, 2025
  2. christerswahn commented on Feb 24, 2025

    @christerswahn
    Contributor

    Would it be worth while to avoid the name context for this, opting for something like client configuration maybe? context is already used in several circumstances.

  3. SandPod commented on Feb 24, 2025

    @SandPod
    ContributorAuthor

    @christerswahn - Yes, that sounds like a good suggestion! The feature does not need to use context as the implementation name.

  4. moved this from Backlog 🗂️ to Planned 🔭 in Serverpod Frameworkson Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: clientenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions