Easy Crud Restful Api Sequelize Mysql NodeJSEasy Crud Restful Api Sequelize Mysql NodeJS
Mysql Database and API Generator from NodeJS Model Sequelize is Online Rest API Generator with expressjs, is use purely JavascriptEasy Crud Restful Api Sequelize Mysql NodeJS
Mysql Database and API Generator from NodeJS Model Sequelize is Online Rest API Generator with ex...Overview
Mysql Database and API Generator from NodeJS Model Sequelize is Online Rest API Generator with expressjs, is use purely Javascript Engine and using MYSQL database.
Mysql is used to manage the data. Mysql Database and API Generator application is combining expressjs and MySQL to build API from the form that you created.
Design your schema & your APIs will be ready in seconds.
# Key benefits
Create Models
Auto generate Controller from Model and Associates
Create Operations
Read Operations
Update Operations
Delete Operations
Conditional Operations
And Statements
Or Statements
Relational Operations
Paginations
Features
Simplified installation and configuration
Easy deployment to production server
Respond quickly to user actions
Load fast and provide an offline experience
Well, structured and clean code
Clean endpoints
Best performance
Build with MVC architecture
Handled errors carefully and explicitly
Carefully designed to fit in any project requirements
Easily Customizable if necessary
Easy to configure
Requirements
Nodejs ^12.x, mysql, sequelize
Instructions
Installing
Step 1: Install VPS server Ubuntu, windows.
Step 2: Install nodejs
sudo apt install nodejs
Step 3: Install yarn
npm install yarn -g
Step 4: Install expressjs
npm install express --save
Step 5: User NodeJS version 12.22.7
sudo npm cache clean -f&&sudo npm install -g n&&sudo n stable&&sudo n 12.22.7
Step 6: NPM install all packages
npm install
Migration database
Step 1: Config database connection pool
Go to file /server/config/config.json Update the config database for your application in this file by JSON format. Example:
{ <span class="hljs-attr">"development"</span>: { <span class="hljs-attr">"username"</span>: <span class="hljs-string">"root"</span>, <span class="hljs-attr">"password"</span>: <span class="hljs-string">""</span>, <span class="hljs-attr">"database"</span>: <span class="hljs-string">"easy_crud_api_test"</span>, <span class="hljs-attr">"host"</span>: <span class="hljs-string">"127.0.0.1"</span>, } }
Step 2: Create database
yarn migration
Running the application
yarn start nodemon ./app.js npm run start
How to use easy-restful-api-sequelize-mysql to make an api fastest?
Define the model
Go to the direction /server/models/ Create an model file, example: post.js and category.js Define the model with the structure of Sequelize Example:
module.exports = (sequelize, DataTypes) => { let fields = { ...require('./base/attributes'), parent_id: { type: DataTypes.INTEGER, allowNull: true }, name: { type: DataTypes.TEXT, allowNull: true, } } const Model = sequelize.define("Category", fields, { tableName: "category", createdAt: false, updatedAt: false }); Model.associate = (models) => { Model.hasMany(models.Category, { foreignKey: 'parent_id' }); Model.belongsTo(models.Category, { foreignKey: 'parent_id', as: 'Parent' }); Model.belongsToMany(models.Post, { through: 'post_has_category', foreignKey: 'category_id', otherKey: 'post_id' }); }; return Model; };
Migration database structure from the model
yarn migration So then, the tables, fields and the associate table has been created successfully.
Create a route for this API
Go to the direction /server/routes/config Create an route config file, example: post.js and category.js Define the route with the structure example like this:
var Controller = require('../../controllers'); module.exports = [ ["get", "/", Controller('Post').list], ["post", "/", Controller('Post').create], ["get", "/:id([0-9]+)", Controller('Post').get], ["put", "/:id([0-9]+)", Controller('Post').update], ["delete", "/:id([0-9]+)", Controller('Post').delete], ]
Run the Application, and test your API by the POSTMAN
yarn start
Other items by this author
Category | Scripts & Code / NodeJS |
First release | 12 January 2023 |
Last update | 12 January 2023 |
Tags | MySQL, API, sequelize, api generator |