Skip to content

Conversation

@DustinJSilk
Copy link
Contributor

@DustinJSilk DustinJSilk commented Oct 30, 2025

What is it?

  • Feature / enhancement

Description

Interfacing with API clients in loaders and server$ functions is a common use case for REST, gRPC, and GraphQL servers.
To share clients on the RequestEvent, the only possible solution is to store it in the sharedMap which makes using them cumbersome:

export const useLoader = routeLoader$(async (ev) => {
  const clients = ev.sharedMap.get("qwik-api-clients");
  const result = await clients.foo.say({ sentence: "Success!" });
});

It would be better to have a DX similar to this:

export const useLoader = routeLoader$(async (ev) => {
  const result = await ev.clients.foo.say({ sentence: "Success!" });
});

To achieve this, we would need to add a getter to the RequestEvent object which returnsev.sharedMap.get("qwik-api-clients").

This way, it's easy for users to extend the RequestEvent with their API clients:

// Register clients by storing them in the sharedMap
export function registerApiClients(ev: RequestEventBase) {
  ev.sharedMap.set("qwik-api-clients", someClientsObject);
}

// Extend the RequestEventBase to add the client types
declare module "@builder.io/qwik-city" {
  interface RequestEventBase {
    clients: SomeClients
  }
}

Checklist

  • My code follows the developer guidelines of this project
  • I performed a self-review of my own code
  • I added a changeset with pnpm change
  • I made corresponding changes to the Qwik docs
  • I added new tests to cover the fix / functionality

@changeset-bot
Copy link

changeset-bot bot commented Oct 30, 2025

⚠️ No Changeset found

Latest commit: 55cd7ad

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@DustinJSilk
Copy link
Contributor Author

For discussion in Discord

@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 55cd7ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant