Nuxt Neo screenshot

Nuxt Neo

Author Avatar Theme by Ezypeeze
Updated: 25 Jul 2024
58 Stars

Universal way to take care of data flow, server or client side

Categories

Overview

The nuxt-neo module is designed to provide middleware API support for Nuxt.js. It allows users to create APIs within Nuxt.js easily, following a controllers and actions approach. This module offers features such as auto-generating routes based on the folder/file tree in the api folder, easy middleware injection, and global HTTP error handling.

Features

  • Auto-generate routes: Routes can be automatically generated based on the folder/file tree in the api folder.
  • Easy middleware injection: Middleware can be injected easily, either for all APIs or specific controllers and actions.
  • Global HTTP Errors: Provides better error handling with global HTTP error support.

Installation

To install nuxt-neo, follow these steps:

  1. Install the module using npm:
npm install nuxt-neo
  1. Import the module in your Nuxt.js configuration file (nuxt.config.js):
module.exports = {
  modules: [
    'nuxt-neo',
  ],
}
  1. Add an api folder in your Nuxt.js project:
mkdir api
  1. Create your API controllers and actions inside the api folder. For example, you can create a UserController.js file with a getUser action:
// api/UserController.js
export default {
  getUser(req, res) {
    // API logic here
  }
}
  1. Access your API endpoints using the generated routes. For example, if you have a UserController with a getUser action, the route will be /api/user/getUser.

Summary

The nuxt-neo module is a useful tool for implementing middleware API support in Nuxt.js. It simplifies the process of creating APIs within Nuxt.js by offering features such as auto-generating routes, easy middleware injection, and global HTTP error handling. By following a controllers and actions approach, developers can easily manage their data flow whether executing code on the server or client side.