Skip to content

feat: Custom Server Routes for external backend api #885

@NyllRE

Description

@NyllRE

🆒 Your use case

Server routes are amazing for testing api routes quickly but in a lot of use cases we could be using an external backend and we want to be able to assign them and test them directly in the devtools.

🆕 The solution you'd like

A method in the /server directory to assign external api routes with the sole purpose to assign external apis, my suggestion is /server/external/api.ts where we can modify the external backend settings directly inside this file:

export default defineExternalApi((event) => {
  const runtimeConfig = useRuntimeConfig()
  event.baseUrl = runtimeConfig.apiBase

  return {
    '/login': {
      method: 'POST',
      headers: [...], // these are defaults that are modifiable
      queries: [...],
      cookies: [...]
    },
    '/logout': {
      method: 'GET',
      ...
    }
  }
})

for compatibility we could build a tool to convert directly from postman or .rest files etc.

🔍 Alternatives you've considered

Implementing a nuxt server route for every single request and routing everything through it but it's absolutely not efficient.

ℹ️ Additional info

I believe this will heavily improve the development experience across teams and if some documentation was able to be implemented directly into them too it would mean that any api service can build with whatever accepted format and plug the documentation directly into nuxt which would make it such a powerful tool for teams and individuals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions