proposal: nuxt internal API route interface
[issue link]Main Benefits
- 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.
- Single api resource definition and use from both server and client.
- 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.