0.2.1 • Published 1 year ago

spw-kobp v0.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

SPW Kobp

Published

Start your Koa project with necessary Boring codes.

Install

npm i --save spw-kobp

# OR

yarn add spw-kobp

NOTE we listed koa as our peerDependencies so please include the koa in your own codebase.

Usage

Start your node.js TypeScript project and describe your endpoints with controller style.

To expose each method as routes. Use our built-in decorator. Route which accepts method, paths, and Koa's middlwares.

controllers/hello.cotnroller.ts

import type { KobpServiceContext } from 'spw-kobp'
import { Route, BaseRoutedController } from 'spw-kobp'

export class HelloController extends BaseRoutedController {

  @Route('post', '/echo')
  async migrate(context: KobpServiceContext) {
    return context.request
  }

  @Route()
  async index(context: KobpServiceContext) {
    return {
      hello: 'world'
    }
  }
}

Or you can describe your controllers in a classical way. (Avoid using decorators). This method introduce less code when it is bundled.

controllers/hello.controller.ts

import type { KobpServiceContext } from 'spw-kobp'
import { RouteMap, BaseRoutedController } from 'spw-kobp'

export class HelloController extends BasedRouteController {

  public getRouteMaps(): RouteMap {
    return {
      ...super.getRouteMaps(),
      index: { method: 'get', path: '/', middlewares: [] }, // Same as our decorator above.
    }
  }

  async index(context: KobpServiceContext) {
    return {
      hello: 'world'
    }
  }
}

Now to utilise this controller. Simply use Koa as your application with our boiler plate.

server.ts

export default makeServer((koa) => {
}, {
  port: 9000
})

By the example above. You will be able to:

curl -XGET http://localhost:9000/hello/hi

TODO

[ ] Example repo
[ ] Inter Service Communication
[ ] SNS/SQS Handler
0.2.1

1 year ago

0.2.0

1 year ago

0.0.44

1 year ago

0.0.42

2 years ago

0.0.43

2 years ago

0.1.8

2 years ago

0.1.9

2 years ago

0.0.40

2 years ago

0.0.41

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.7

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.0.36

3 years ago

0.0.37

3 years ago

0.0.38

3 years ago

0.0.39

3 years ago

0.0.35

3 years ago

0.0.34

3 years ago

0.0.33

3 years ago