Skip to content

How should I do x-api-key in serverpod Endpoint? #4892

Closed as duplicate
Closed as duplicate

Description

@thangmoxielabs

Problem to Solve

Having an x-api-key to validate requests is a common practice. However, there isn't a solution works ootb. Unless I'm wrong, but there isn't a way to add customHeaders to the generated Client class. On the server side, there isn't a middleware or plugin to verify all request (or scoping) including such header. We have to have a helper function and make sure it's called on every Endpoint request

Proposal

Add support for customHeaders, and provide middleware/plugin to allow adding guard without having to update all existing endpoints

Use Case

Verifying x-api-key on the server side to validate requests

Alternatives

I can't think of any

Additional context

No response

How experienced are you with this library?

Intermediate - Familiar with the basics or have used it in a few projects

Are you interested in working on a PR for this?

  • I want to work on this

Activity

  1. added
    enhancement
    on Mar 25, 2026
  2. added
    area: client
    on Mar 27, 2026
  3. marcelomendoncasoares commented on Mar 27, 2026

    @marcelomendoncasoares
    Collaborator

    Hi @thangmoxielabs! Thanks for reaching out!

    Indeed, currently it is not possible to add arbitrary headers to the client. However, this is something that we should do together with refactoring the routing inside Serverpod (and maybe exposing control over the method and parameters).

    Since we already have a detailed issue that covers this request, I'll close this one as duplicated, but feel free to comment there about your use case!

  4. moved this from Inbox 📫 to Done 🚀 in Serverpod Frameworkson Mar 27, 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