fern icon indicating copy to clipboard operation
fern copied to clipboard

[Feature] Custom headers on API requests in fern spec

Open gregorybchris opened this issue 1 year ago • 3 comments

Problem description

It would be great to be able to send arbitrary headers on requests from the SDK to the API. Fern currently supports the headers X-Fern-SDK-Language and X-Fern-SDK-Version, but if a Fern user wants to send a different header on all requests from their SDK that's not currently possible. This feature request is to provide some configuration option in the fern spec to send an arbitrary header.

Why would it be useful?

Client information is very useful to maintain in server-side telemetry. Allowing the configuration of arbitrary headers in the fern spec helps in scenarios when server code is not easily accessible. This can make the Fern onboarding process a lot easier as the user can update a single line in the Fern config and conform to the API's expectations for header metadata without updating the API.

More details

This may be included in the generators.tml under generator config. Perhaps something like:

config:
  headers:
    X-My-Own-Header: "my-own-header-value"
    X-My-Other-Header: "my-other-header-value"

Though I don't have enough experience with the Fern spec to know if there's a better place/format for this configuration.

gregorybchris avatar Jan 09 '24 17:01 gregorybchris

Hi there @gregorybchris is something like this what you have in mind?: https://docs.buildwithfern.com/api-definition/fern-definition/api-yml-reference#global-headers

armandobelardo avatar Jan 09 '24 17:01 armandobelardo

Hey @armandobelardo! If I'm reading this correctly, this is specifying which headers the API can accept on requests, right?

Whereas I'm more talking about configuring the SDK to send a specific header and value to the API on every request. It would be more similar to the existing X-Fern-SDK-Language and X-Fern-SDK-Version headers which are sent on every request, except configurable by the Fern user.

gregorybchris avatar Jan 09 '24 18:01 gregorybchris

@gregorybchris this should do what you're asking for if you assign the header to a literal! If you're leveraging an OpenAPI spec, the config would be based on: https://docs.buildwithfern.com/api-definition/openapi/open-api-extensions#global-headers

x-fern-global-headers:
  - header: X-My-Own-Header
    name: myOwnHeader
    type: literal<"my-own-header-value">

armandobelardo avatar Mar 10 '24 16:03 armandobelardo