villeristi / express-typescript-api-boilerplate

Boilerplate for Express API's build with TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Express & TypeScript API-Boilerplate

A full-blown Express RESTful API-boilerplate written in TypeScript.

Build Status Awesome

Build with:

Getting started

  1. Be sure you have Yarn installed globally.
  2. Clone the repo & run yarn from the project root

Configuration

Middleware-functions can be addedd though App.use(middleWareFunction()). Configs can be array of middlewares or a single middleware-function where the second argument is a boolean which states if this middleware should be enabled. See index.ts as example.

Routing

Each route added with App.route() has to extend the abstract BaseRoute-class or CrudRoute-class with overridden members:

BaseRoute

  • method: string (http-verb)
  • endpoint: string (the actual route)
  • middleware: array (optional middleware-functions for this specific route)
  • respond(): Response

CrudRoute

  • endpoint: string (the actual route)
  • middleware: array (optional middleware-functions for this specific route)
  • [HTTP-VERB](): Response: HTTP-verbs which this route supports. For example, if there's no PUT-method defined & PUT-request is coming to this route => an Exception is thrown.

See modules as example.

Available commands:

  • yarn start: Executes Nodemon & refreshes app on file-change
  • yarn lint: Executes TSLint & TypeScript tsc (typecheck)
  • yarn build Builds app as regular Javascript (es2015) to /dist

Todo:

  • Route-middleware
  • Resourseful routing
  • Unit tests
  • ...?

About

Boilerplate for Express API's build with TypeScript


Languages

Language:TypeScript 100.0%