LuvDaSun / SkiffaGenerator

ISC License
2 stars 2 forks source link

Feature request: Implement scoped default headers for SDK client #111

Open mgm1313 opened 2 weeks ago

mgm1313 commented 2 weeks ago

I'd like a straightforward way to set default headers for requests. This is important for us because we use headers like Accept-Language and User-Agent for analytical purposes, among other things.

The api could extend the one proposed in #110 :

export async function createAgent({
  domain,
  locale,
}: AgentProps) {
  const baseUrl = someLogicToDetermineBaseUrl(domain);
  const userAgent = getVersionString()

  const agent = new sdk.client({
    defaultConfiguration: {
      baseUrl: new URL(baseUrl),
      headers: {
        'Accept-Language': locale,
        'User-Agent': userAgent,
      }
    }
  });
  return agent;
}