Static GitHub Issues

[402] proposal: nuxt internal API route interface

prev: nuxt fetch and middleware life cycle
next: Can’t get nested routes to work with a slug

Main Benefits 1. Take advantage of webpack HMR for API. Currently, when using nuxt.render middleware, the entire project restarts and takes significant amount of time to work on backend api work. 2. Single api resource definition and use from both server and client. 3. Removes need for - express - proxy route - reduces ssr latency by eliminating the http call

Using express routes as an example

api.get('/users', async function(req,res) {
  res.send( await Users.find() )
}

If we can make api a resource also available from the client and automatically bound to the route defined

Sample component

import api from '~api'
module.exports = {
 async data () {
  users: await api.get('/users')
 }
}

Api now will be universal and depending on the runtime environment will toggle between actually running the route from the server or hitting the api end point from the client.

I know this is real rough and high level - it may also conflict with what nuxt stands for. I'm not sure if we want to be agnostic in server api implementations. However, as nuxt currently stands, there is quite a bit of work a developer must go through before having a workable implementation with the server.

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This feature request is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c345">#c345</a>)</em></sub></div>