Skip to content

amrecords/nodejs-express-restapi-mysql-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple REST API based on node.js with mysql connectivity

addition

Der Text wird etwas länger

This is a simple example of how you can build a REST API based on nodejs with a mysql db as data store.

Getting started

  1. get the code : git clone
  2. install dependecies : npm install
  3. create a local mysql database and create the table user in it, see mysql table
  4. define the mysql credentials in server.js
  5. start the rest api server : npm start

REST API

User Management

GET http://localhost:8081/api/users
POST http://localhost:8081/api/users
{
	"email": "[email protected]",
	"name": "neuer name",
	"password": "meinpassword",
}

GET http://localhost:8081/api/users/[email protected]


PUT http://localhost:8081/api/users/[email protected]

{
	"name": "neuer name",
	"password": "meinpassword"
}

DELETE http://localhost:8081/api/users/[email protected]


Auth

POST http://localhost:8081/api/auth

POST http://localhost:8081/api/auth
{
	"email": "[email protected]",
	"password": "meinpassword",
}

MySQL table


CREATE TABLE IF NOT EXISTS `user` (
  `id` int(70) NOT NULL AUTO_INCREMENT,
  `email` varchar(45) NOT NULL,
  `name` varchar(45) NOT NULL,
  `groups` varchar(1024) NULL,
  `password` varchar(45) DEFAULT NULL,
  `join_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_UNIQUE` (`email`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%