Skip to content

Support for Custom URL Prefixes for API Clients #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
schplitt opened this issue May 6, 2025 · 1 comment
Open

Support for Custom URL Prefixes for API Clients #2017

schplitt opened this issue May 6, 2025 · 1 comment
Labels
feature 🚀 New feature or request

Comments

@schplitt
Copy link

schplitt commented May 6, 2025

Description

Hello,

I am currently working with multiple API clients and openapi-ts is a godsend for me. My project involves a multitenancy setup, where each client needs a distinct prefix derived from the file name and still use the windows location as the baseURL. Unfortunately, the current implementation only supports the baseUrl option, which does not accommodate my needs as I do not have a single set URL.

Feature Request:

I would like to request the ability to set a custom URL prefix for each API client. Specifically, I propose adding support for a prefix pattern like /services/{filename}/, where {filename} is dynamically replaced with the name of the API file. This would allow the resulting URL for each client to be structured as follows:

{window.location.origin}/{customPrefix}/{...apis from file}

Example:

Given an API file named storageService, the resulting URL for the client would be:

{window.location.origin}/services/storageService/{...apis from file}

Current Script:

openAPIFiles.forEach((file) => {
  const fullPath = path.join(openAPIFilesDir, file)
  const fileName = path.basename(file, path.extname(file))

  createClient({
    input: fullPath,
    output: path.join(clientTargetDir, fileName),
    plugins: [{
      name: '@hey-api/client-fetch',
    }],
  })
})

Proposed Script with Solution:

openAPIFiles.forEach((file) => {
  const fullPath = path.join(openAPIFilesDir, file)
  const fileName = path.basename(file, path.extname(file))

  createClient({
    input: fullPath,
    output: path.join(clientTargetDir, fileName),
    plugins: [{
      name: '@hey-api/client-fetch',
      prefix: "service/" + fileName
    }],
  })
})

Benefits:

  • Simplifies the management of multiple API clients in a multitenancy environment.
  • Enhances flexibility by allowing dynamic URL generation

Thank you for considering this feature request. I believe it would greatly enhance the usability and flexibility of the library for developers working in similar environments.

@schplitt schplitt added the feature 🚀 New feature or request label May 6, 2025
@schplitt
Copy link
Author

schplitt commented May 6, 2025

I work alot with Nuxt/Nitro so maybe calling apiBaseURL is a better idea to impove comaptibility.
https://nitro.build/config#apibaseurl

Scratch that, this is for the api itself in nitro.
Nitro already uses baseURL for this purpose.
Maybe it makes sense to just allow the prefix in baseURL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🚀 New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant