Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

remembercode/mysql-restful-api

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mysql-restful-api

线上效果:http://172.104.79.155:4000/restful/admin/#/user/list

示例代码仓库:https://github.com/postor/mysql-restful-api-example

给每个表生成对应的restful接口文件,作为Router使用在你的express项目中。|generate files for restful api for each table, require them as routers and use in your app

  • 可用于现有的express项目|designed for an working express
  • 所有的逻辑都是生成的,都可以改|more flexable

用到的项目|related projects

如果不是现有的项目,就新建一个|prepare a working express if you don't have one

mkdir myproj
cd myproj
npm init
npm install express --save
vi app.js #copy code into app.js
node app.js

app.js

var express = require('express');
var app = express();

// respond with "hello world" when a GET request is made to the homepage
app.get('/', function(req, res) {
  res.send('hello world');
});

app.listen(80)

使用本项目生成restful代码|use this to generate code

npm install mysql-restful-api --save
node node_modules/mysql-restful-api/cli.js
#path_for_generated_files
#host
#user
#password
#db
#done!
vi app.js

应用这些生成的代码|use generated code

app.js

var express = require('express');
var app = express();
app.use('/restful',require('./restful/default-router'))
// respond with "hello world" when a GET request is made to the homepage
app.get('/', function(req, res) {
  res.send('hello world');
});

app.listen(80)

定制情况(自由发挥)|cases

//default
app.use('/restful',require('./restful/default-router'))

//only table
app.use('/table1',require('./restful/routers/table1')))

定制Router的实现(具体修改自由发挥)|customize table router/actions

vi path_for_generated_files/table_name #and modify it

默认的restful规则|restful standard

  • listView => GET /users
  • creationView => POST /users
  • showView => GET /users/:id
  • editionView => PUT /users/:id
  • deletionView => DELETE /users/:id

/restful/test_table/1

  {"id":1,"name":"2017-01-13 12:56:25"}

后台管理页面|admin page

/restful/admin/

常见问题|Q&A

Error: ER_NOT_SUPPORTED_AUTH_MODE

mysql终端

update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';
flush privileges;

About

nodejs对mysql的restful服务,所有的逻辑代码都是生成的,都可以修改,而且提供了管理后台的页面!mysql to restful for node, all generated, all under control, with admin page!

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 96.5%
  • HTML 3.5%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.