All Projects → Q00 → Api_server_boilerplate

Q00 / Api_server_boilerplate

Licence: mit
typescript express board boilerplate using routing controller

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Api server boilerplate

Node Typescript Boilerplate
Minimalistic project template to jump start a Node.js back-end application in TypeScript. ESLint, Jest and type definitions included.
Stars: ✭ 1,061 (+1940.38%)
Mutual labels:  service, starter-template, project-template
Aspnetcore Webapi Course
Professional REST API design with ASP.NET Core 3.1 WebAPI
Stars: ✭ 323 (+521.15%)
Mutual labels:  swagger, sentry, oauth
server-action-service
Generic and reusable Lightning service component that calls server-side actions
Stars: ✭ 19 (-63.46%)
Mutual labels:  service, action
Grant
OAuth Proxy
Stars: ✭ 3,509 (+6648.08%)
Mutual labels:  server, oauth
Meiam.system
.NET 5 / .NET Core 3.1 WebAPI + Vue 2.0 + RBAC 企业级前后端分离权限框架
Stars: ✭ 340 (+553.85%)
Mutual labels:  swagger, service
Bus
Bus 是一个基础框架、服务套件,它基于Java8编写,参考、借鉴了大量已有框架、组件的设计,可以作为后端服务的开发基础中间件。代码简洁,架构清晰,非常适合学习使用。
Stars: ✭ 253 (+386.54%)
Mutual labels:  swagger, oauth
sparky
A Bootstrap 3 and 4 Sass Starter Project
Stars: ✭ 21 (-59.62%)
Mutual labels:  project-template, starter-template
Pode
Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
Stars: ✭ 329 (+532.69%)
Mutual labels:  swagger, server
Openapi Core
OpenAPI core
Stars: ✭ 119 (+128.85%)
Mutual labels:  swagger, server
Swagger Express Middleware
Swagger 2.0 middlware and mocks for Express.js
Stars: ✭ 543 (+944.23%)
Mutual labels:  swagger, server
Awesome Openapi3
😎 A list of awesome projects related to OpenAPI 3.0.x, curated by the community
Stars: ✭ 469 (+801.92%)
Mutual labels:  swagger, server
Redux Webpack Es6 Boilerplate
A starter project for modern React apps with Redux
Stars: ✭ 566 (+988.46%)
Mutual labels:  starter-template, sentry
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+6530.77%)
Mutual labels:  swagger, server
Templates
.NET project templates with batteries included, providing the minimum amount of code required to get you going faster.
Stars: ✭ 2,864 (+5407.69%)
Mutual labels:  swagger, project-template
login-server
Login and connect accounts with multiple identity providers
Stars: ✭ 28 (-46.15%)
Mutual labels:  oauth, service
Faygo
Faygo is a fast and concise Go Web framework that can be used to develop high-performance web app(especially API) with fewer codes. Just define a struct handler, faygo will automatically bind/verify the request parameters and generate the online API doc.
Stars: ✭ 1,557 (+2894.23%)
Mutual labels:  swagger, server
Appserver
A multithreaded application server for PHP, written in PHP.
Stars: ✭ 930 (+1688.46%)
Mutual labels:  service, server
Moqui Framework
Use Moqui Framework to build enterprise applications based on Java. It includes tools for databases (relational, graph, document), local and web services, web and other UI with screens and forms, security, file/resource access, scripts, templates, l10n, caching, logging, search, rules, workflow, multi-instance, and integration.
Stars: ✭ 205 (+294.23%)
Mutual labels:  service, server
Appy Backend
A user system to bootstrap your app.
Stars: ✭ 96 (+84.62%)
Mutual labels:  swagger, server
Livego
go Implementation of live streaming services
Stars: ✭ 411 (+690.38%)
Mutual labels:  service, server

Welcome to api_server_boilerplate 👋

Version Documentation License: MIT Cody Style: Google

easy to use typescript express boilerplate. You can use board api, user api, error tracking etc..


🏠 Homepage

Install

yarn install
# after put your env flie
yarn db:dev sync # development environment
# or
yarn db:sync # production environment

Usage

yarn dev # development environment
yarn start # production environment

Run tests

yarn prepare
yarn build
yarn test

Or you can use debug with vscode

code

model

There are base models. You can extend this base models.

Base model

export abstract class BaseModel {
  @IsInt()
  @Generated('increment')
  @PrimaryColumn({ type: 'bigint', transformer: [bigIntTransformer] })
  id!: number;

  @IsDate()
  @CreateDateColumn()
  createdAt!: Date;

  @IsDate()
  @UpdateDateColumn()
  updatedAt!: Date;

  @IsDate()
  @Column({ nullable: true, type: 'date', default: null })
  deletedAt?: Date | null;
}

Also There are base board, base comment model.

Base board model

// you can extends this class making child board and add user

export abstract class BaseBoard extends BaseModel {
  @Column({ length: 50 })
  @IsString()
  title!: string;

  @IsString()
  @Column({ type: 'text' })
  content!: string;

  @IsInt()
  @Column({ default: 0 })
  reportCount!: number;
}

Base comment model

// you can extends this class making child comment and add user

export abstract class BaseComment extends BaseModel {
  @Column({ length: 50 })
  @IsString()
  @MaxLength(50)
  comment!: string;

  @Column({ default: 0 })
  @IsInt()
  reportCount!: number;
}

service

Threr are base services. You can extend this base services to other child service.

Base service

// you can extends this BaseService to use common method

export abstract class BaseService<T extends BaseModel> {
  protected genericRepository: Repository<T>;
  private repo: ObjectType<T>;
  constructor(repo: ObjectType<T>) {
    this.genericRepository = getConnection().getRepository(repo);
    this.repo = repo;
  }
}

And then you just call super call with your using repository

  constructor() {
    super(RepoName);
  }

Base board service

@Service()
export abstract class BaseBoardService<T extends BaseBoard> extends BaseService<
  T
> {
  constructor(repo: ObjectType<T>) {
    super(repo);
  }
}

This service is base board service. In this service, there are common method about board. You can extend this service to other child board service.

Base comment service

export abstract class BaseCommentService<
  T extends BaseComment
> extends BaseService<T> {
  constructor(repo: ObjectType<T>) {
    super(repo);
  }
}

This service is base comment service. This service is very similar to base board service.

Provider

This module makes OAUTH logic. You can use base provider to extends other OAUTH.

export abstract class BaseProvider {
  protected accessToken: string;
  protected instance: AxiosInstance | null;
  constructor() {
    this.accessToken = '';
    this.instance = null;
  }
  setToken(accessToken: string) {
    this.accessToken = accessToken;
  }

  setInstance(url: string, headers: object) {
    this.instance = apiClient(url, headers);
    this.instance.interceptors.response.use(
      (response) => response,
      (err) => Promise.reject(err),
    );
  }

  getInstance() {
    return this.instance;
  }

  async generateToken(userId: number) {
    return `Bearer ${Authentication.generateToken(userId)}`;
  }
}

Auth Conroller use this provider to make JWT token.

Controller

There are BaseAuthController, BaseCommentController and Other Controller. This project use routing-controllers and typedi. Thier README help you understand this architecture.

Base Auth Controller

export class BaseAuthController<T extends BaseProvider> extends BaseController {
  // this can be used in child class (ExampleAuthController)
  protected userAccountService: UserAccountService;
  protected userService: UserService;
  constructor(protected provider: T) {
    super();
    this.provider = provider;
    this.userAccountService = Container.get(UserAccountService);
    this.userService = Container.get(UserService);
  }
}

Base Comment Controller

export abstract class BaseCommentController<
  U extends BaseComment,
  T extends BaseCommentService<U>
> extends BaseController {
  protected service: T;
  constructor(service: T) {
    super();
    this.service = service;
  }
}

If you want to extends this controller, you should call super with service like below.

@JsonController('/example_board_comment')
export class ExampleBoardCommentController extends BaseCommentController<
  ExampleBoardComment,
  ExampleBoardCommentService
> {
  //this private service automaticaly injected by typedi
  constructor(private exampleBoardCommentService: ExampleBoardCommentService) {
    super(exampleBoardCommentService);
  }
}

DTO

To make request schema, this project use class-validator. This request schema will be shown in swagger ui or Redoc.

Interceptor

This module use routing-controllers interceptor

Middleware

This module use routing-controllers Middleware

Database

This project use typeorm and connect with Postgres.

Naming Strategy

using snake case.

export class NamingStrategy extends DefaultNamingStrategy {
  tableName(targetName: string, userSpecifiedName: string | undefined): string {
    return plural(snakeCase(userSpecifiedName || targetName));
  }

  relationName(propertyName: string): string {
    return snakeCase(propertyName);
  }

  columnName(propertyName: string, customName: string) {
    return snakeCase(customName || propertyName);
  }

  joinColumnName(relationName: string, referencedColumnName: string) {
    return snakeCase(`${relationName}_${referencedColumnName}`);
  }

  joinTableColumnName(
    tableName: string,
    propertyName: string,
    columnName: string,
  ) {
    return snakeCase(`${tableName}_${columnName || propertyName}`);
  }
}

config

const typeOrmConfig: PostgresConnectionOptions = {
  type: 'postgres',
  host: process.env.DB_HOST,
  namingStrategy: new NamingStrategy(),
  port: Number(process.env.DB_PORT),
  username: process.env.DB_USER,
  password: process.env.DB_PW,
  database: process.env.DATABASE,
  synchronize: false,
  logging: false,
  entities: [`${path.join(__dirname, '..', 'model')}/**.[tj]s`],
  migrations: [`${path.join(__dirname, '..', 'model')}/migration/**.[tj]s`],
};

Env variable

DB_HOST=
DB_USER=
DB_PW=
PORT= # your server port
DB_PORT=
DATABASE= # database name
TEST_TOKEN= # jwt token to use in testing
SENTRY_DSN= # sentry dsn

Author

👤 Q00 [email protected]

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.
If you want to contribute this repo, check contribute page

🔍 Relase note && Change log

Release note and change log are exist in CHANGELOG

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].