Giter Site home page Giter Site logo

rest-express's Introduction

rest-express

项目介绍

express rest api with mongodb and mysql

Rest-Express

安装APIDOC自动生成api文档

api-doc

自动生成接口api文档

apidoc -i routes/ -o public/apidoc/

替代方案可以使用swagger

REST接口写法

```
/**
 * @api {get} /api/users 用户列表
 * @apiDescription 用户列表
 * @apiName getUserList
 * @apiGroup User
 * @apiParam {string} loginName 用户名
 * @apiParam {string} loginPass 密码
 * @apiSuccess {json} result
 * @apiSuccessExample {json} Success-Response:
 *  {
 *      "success" : "true",
 *      "result" : {
 *          "name" : "loginName",
 *          "password" : "loginPass"
 *      }
 *  }
 * @apiSampleRequest http://localhost:3000/api/user
 * @apiVersion 0.1.0
 */
router.get('/', function (req, res, next) {
    controller.findAll().then(result => {
        if (result) {
            res.send(result);
        } else {
            res.send('nothing can be found');
        }
    });
    next();
});

router.get('/:id', function (req, res, next) {
    controller.findById(req.params.id).then(result => {
        res.send(result);
    }).catch(err => {
        res.send(err);
    });
    next();
});

router.post('/', function (req, res, next) {
    res.send('respond with a resource');
    next();
});

router.put('/:id', function (req, res, next) {
    if (!req.params.id) {
        res.send('id 不能为空');
    } else {
        controller.findOneAndUpdate(req.params.id, req.body).then(result => {
            res.send(req.body);
        }).catch(err => res.send(err));
    }
    next();
});

router.delete('/:id', function (req, res, next) {
    res.send('respond with a resource');
    next();
});

```

HTTP

api-doc

文件结构

client      -- pwa  前端项目
public      -- node 公共文件
routes      -- node 服务端路由
service     -- node 服务端业务逻辑 
test        -- node 模块测试文件
uploads     -- file 接收上传的文件

软件架构

nodejs  10.14
express ^4.16.0
mysql   ^5.6-8.0
mongodb 4.04

安装并开发

  1. git clone https://github.com/guobin211/rest-express.git
  2. npm install
  3. npm run nodemon

使用说明

  1. 确保安装所有运行环境
  2. 使用默认配置启动mongodb和mysql数据库
  3. npm run start 或者使用 pm2启动

rest-express's People

Contributors

guobin211 avatar

Stargazers

 avatar yangsheng avatar  avatar

Watchers

James Cloos avatar

Forkers

ys22

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.