DEV Community

loizenai
loizenai

Posted on

Angular 6 HttpClient Crud + Node.js Express Sequelize + MySQL

Angular 6 HttpClient Crud + Node.js Express Sequelize + MySQL - Get/Post/Put/Delete RestAPIs

https://grokonez.com/frontend/angular/angular-6/angular-6-httpclient-node-js-express-sequelize-mysql-get-post-put-delete-restapis

Sequelize is a promise-based ORM for Node.js v4 and later. In the tutorial, we will show how to GET/POST/PUT/DELETE requests from Angular 6 Client to MySQL with NodeJs/Express RestAPIs using Sequelize ORM.

Related posts:

Technologies

  • Angular 6
  • RxJS 6
  • Bootstrap 4
  • Visual Studio Code – version 1.24.0
  • Nodejs – v8.11.3
  • Sequelize
  • MySQL

Overview

Demo

Goal

We create 2 projects:

– Angular Client Project:

angular-6-http-client-nodejs-express-restapis-sequelize-orm-mysql +angular-6-client-project-structure

– Node.js RestAPIs project:

angular-6-http-client-nodejs-express-restapis-sequelize-orm-mysql +nodejs-project-structure

UserCase

Start Node.js server -> Logs:


> node server.js

App listening at http://:::8080
Executing (default): DROP TABLE IF EXISTS `customers`;
Executing (default): DROP TABLE IF EXISTS `customers`;
Executing (default): CREATE TABLE IF NOT EXISTS `customers` (`id` INTEGER NOT NULL auto_increment , `firstname` VARCHAR(255), `lastname` VARCHAR(255), `age` INTEGER, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `customers`
Drop and Resync with { force: true }
Executing (default): INSERT INTO `customers` (`id`,`firstname`,`lastname`,`age`,`createdAt`,`updatedAt`) VALUES (1,'Joe','Thomas',36,'2018-07-06 13:01:05','2018-07-06 13:01:05');
Executing (default): INSERT INTO `customers` (`id`,`firstname`,`lastname`,`age`,`createdAt`,`updatedAt`) VALUES (2,'Peter','Smith',18,'2018-07-06 13:01:05','2018-07-06 13:01:05');
Executing (default): INSERT INTO `customers` (`id`,`firstname`,`lastname`,`age`,`createdAt`,`updatedAt`) VALUES (3,'Lauren','Taylor',31,'2018-07-06 13:01:05','2018-07-06 13:01:05');
Executing (default): INSERT INTO `customers` (`id`,`firstname`,`lastname`,`age`,`createdAt`,`updatedAt`) VALUES (4,'Mary','Taylor',24,'2018-07-06 13:01:05','2018-07-06 13:01:05');
Executing (default): INSERT INTO `customers` (`id`,`firstname`,`lastname`,`age`,`createdAt`,`updatedAt`) VALUES (5,'David','Moore',25,'2018-07-06 13:01:05','2018-07-06 13:01:05');
Executing (default): INSERT INTO `customers` (`id`,`firstname`,`lastname`,`age`,`createdAt`,`updatedAt`) VALUES (6,'Holly','Davies',27,'2018-07-06 13:01:05','2018-07-06 13:01:05');
Executing (default): INSERT INTO `customers` (`id`,`firstname`,`lastname`,`age`,`createdAt`,`updatedAt`) VALUES (7,'Michael','Brown',45,'2018-07-06 13:01:05','2018-07-06 13:01:05');

– Angular client retrieve all customers from Node.js RestAPIs:

angular-6-http-client-nodejs-express-restapis-sequelize-orm-mysql +angular-6-client-retrieve-all-customeres

– Angular client update a customer -> Change the firstname of first customer: ‘Joe’ to ‘Robert’.

angular-6-http-client-nodejs-express-restapis-sequelize-orm-mysql +angular-6-client-edit-customer

-> result:

angular-6-http-client-nodejs-express-restapis-sequelize-orm-mysql +update-customer

– Delete ‘Peter’ customer:

– Delete <em>‘Peter’</em> customer:

– Add a new customer:

angular-6-http-client-nodejs-express-restapis-sequelize-orm-mysql + add-customer

-> result:

angular-6-http-client-nodejs-express-restapis-sequelize-orm-mysql +submmit-customer-successfully

– Check final customer’s list:

angular-6-http-client-nodejs-express-restapis-sequelize-orm-mysql +final-check

https://grokonez.com/frontend/angular/angular-6/angular-6-httpclient-node-js-express-sequelize-mysql-get-post-put-delete-restapis

Top comments (0)