Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s-pro/koa2-starter
Koa2 starter RESTful application
https://github.com/s-pro/koa2-starter
koa koa2 koajs mysql nodejs sequelize
Last synced: about 1 month ago
JSON representation
Koa2 starter RESTful application
- Host: GitHub
- URL: https://github.com/s-pro/koa2-starter
- Owner: S-PRO
- Created: 2017-01-22T08:31:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-08T22:00:40.000Z (over 7 years ago)
- Last Synced: 2024-10-14T01:22:31.244Z (about 1 month ago)
- Topics: koa, koa2, koajs, mysql, nodejs, sequelize
- Language: JavaScript
- Homepage:
- Size: 55.7 KB
- Stars: 6
- Watchers: 9
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:allRun 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
```json
{
"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
```json
{
"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]
```json
{
"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]
```json
{
"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
```json
"204 No Content"
```## TODO
- [ ] Add unit tests
- [ ] Move validator to separate repo
- [ ] Add production deployment system
- [ ] Add /login && /posts
- [ ] Add auth checking
- [ ] Add ACLs