• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

S-PRO/koa2-starter: Koa2 starter RESTful application

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

S-PRO/koa2-starter

开源软件地址:

https://github.com/S-PRO/koa2-starter

开源编程语言:

JavaScript 100.0%

开源软件介绍:

Koa2 starter REST API application

Technologies:

  • Koa v2
  • MySQL
  • JSON Schema
  • Yarn
  • ESLint
  • Git hooks

Getting started

Create data base:

CREATE DATABASE `koa2-starter` CHARACTER SET utf8 COLLATE utf8_general_ci;

Install Sequelize CLI:

$ npm i -g sequelize-cli

Install dependencies:

$ yarn install

Make migrations and seeds:

$ sequelize db:migrate
$ sequelize db:seed:all

Run locally:

$ npm start

Project structure

.
└── app/  --> Application files
    ├── config/
    |   ├── app.confg.js    --> App config: port, base url, etc...
    |   └── database.json   --> databes configuration file generated by sequelize cli
    ├── middlewares/  --> All custom middlewares should be stored in this folder
    ├── migrations/   --> Migrations generated by sequelize cli
    ├── models/       --> Models generated sequelize cli
    ├── seeders/      --> Seeds generated sequelize cli
    ├── src/          --> All endpoints should be stored inside this folder
    |   └── user/
    |       ├── router.js           --> Required file. Should be inside each endpoint. Contains koa router instance.
    |       ├── user.controller.js  --> Routes handlers
    |       └── schemas/
    |           ├── index.js            --> Collect all schemas  
    |           └── create.schema.json  --> JSON Schema
    ├── utils/        --> Application common utils
    └── index.js      --> Application entry point

Endpoints

$ http GET localhost:3000/user
{
  "users": [
    {
      "createdAt": "2017-01-22T14:21:46.000Z",
      "email": "[email protected]",
      "first_name": "foo",
      "id": 4,
      "last_name": "bar",
      "status": "active",
      "updatedAt": "2017-01-22T14:21:46.000Z"
    }
  ]
}
$ http GET localhost:3000/user/:id
{
  "user": {
    "createdAt": "2017-01-22T14:21:46.000Z",
    "email": "[email protected]",
    "first_name": "foo",
    "id": 4,
    "last_name": "bar",
    "status": "active",
    "updatedAt": "2017-01-22T14:21:46.000Z"
  }
}
$ http POST localhost:3000/user first_name=foo last_name=bar password=qwerty [email protected]
{
  "user": {
    "createdAt": "2017-01-22T14:21:46.000Z",
    "email": "[email protected]",
    "first_name": "foo",
    "id": 4,
    "last_name": "bar",
    "status": "active",
    "updatedAt": "2017-01-22T14:21:46.000Z"
  }
}
$ http PUT localhost:3000/user first_name=another_name last_name=bar [email protected]
{
  "user": {
    "createdAt": "2017-01-22T14:21:46.000Z",
    "email": "[email protected]",
    "first_name": "another_name",
    "id": 4,
    "last_name": "bar",
    "status": "active",
    "updatedAt": "2017-01-22T14:21:46.000Z"
  }
}
$ http DELETE localhost:3000/user/:id
"204 No Content"

TODO

  • Add unit tests
  • Move validator to separate repo
  • Add production deployment system
  • Add /login && /posts
  • Add auth checking
  • Add ACLs



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap