/rest

Rest is a simple Typescript Koa2 RESTful api stater.

Primary LanguageTypeScriptMIT LicenseMIT

REST (under development)

Rest is a simple Typescript Koa2 api stater. It's my first typescript program and is a project aim to reduce my development costs

Framework Used in this project:

  • Koa
  • Joi
  • PassportJS

The structure:

The design of this restful api has been inspired by this article Project structure for an Express REST API when there is no “standard way”.The architecture diagram below shows the main idea.

diagram

Controllers: You should never put any logic in controller layer. They call the service , which contain pure business logic Service: should contain the majority of your business logic, that calls your data access layer or model

Model:

To create an new project you will need to init sequelize model. Please read Sequelize migrations for futher information. Once you finished your database initiation, modify smaple/example.js and copy into your rest/component/<something> folder

Module-alias:

module alias

  // "_moduleAliases": {
  //   "@config": "<rootDir>/src/config",
  //   "@interfaces": "<rootDir>/src/interfaces",
  //   "@services": "<rootDir>/src/services",
  //   "@components": "<rootDir>/src/rest/components"
  // },
Alias
@config
@interface
@services

Start up the application:

run SET NODE_ENV=<DEV|PROD> in cmd then run npm run start