1.0.0-alpha.0 • Published 3 years ago

ts-actionpack v1.0.0-alpha.0

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

TS Action Pack

Tiny library to help writing "one controller instance per request" style backend in typescript.

This library includes:

The aim is to provide something simple but type-safe equivalent of Ruby on Rails Action Pack.

Usage

import * as express from "express";
import { makeRouterDSL, AbstractController } from "ts-actionpack";

// Define controller
class HomeController extends AbstractController {
  index() {
    this.res.send("Hello");
  }
  show() {
    this.res.send(`Hello: id = ${this.req.params.id}`);
  }
}

// Define router
const router = express.Router();
const { GET } = makeRouterDSL(router);

GET("/", HomeController, "index");
GET("/:id", HomeController, "show");

// Use router
const app = express();
app.use(router);
app.listen(8080);

Examples

Via controller inheritance, it's easy to extend functionalities e.g.

See more examples at tests/examples.

Development

# Development
npm install
npm run build -- -w

# Run example
npm run example -- ex00-simple

# Testing
npm run test

# Formating
npm run format

# Publish
npm run deploy
1.0.0-alpha.0

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago