feat: Custom Server Routes for external backend api
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.3k
- Forks
- 214
- Avg merge
- 13h 22m
- Merged PRs (30d)
- 18
Description
🆒 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the proposed /server/external/api.ts entry point and how existing Nuxt server routes are configured. Determine how defineExternalApi, runtimeConfig.apiBase, route methods, headers, queries, and cookies would fit together; done means external APIs can be assigned and tested in DevTools without a separate server route for every request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nuxt, typescript
- Domain
- api, developer-experience, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100