# kolp

> Build microservice on Lambda using Koa

Latest version **2.1.3** (published 2024-01-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install kolp
pnpm add kolp
yarn add kolp
bun add kolp
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.3 |
| Published | 2024-01-19 |
| First published | 2020-12-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 101.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Kittiphat S. |
| Maintainers | peatiscoding |
| Keywords | lambda, koa, koa-router, serverless, serverless-http |

## Links

- npm: https://www.npmjs.com/package/kolp
- Repository: https://github.com/peatiscoding/kolp
- Homepage: https://github.com/peatiscoding/kolp#readme
- Issues: https://github.com/peatiscoding/kolp/issues
- npm.io page: https://npm.io/package/kolp

## Dependencies (3)

- [@koa/router](https://npm.io/package/@koa/router.md) ^8.0.8
- [koa-bodyparser](https://npm.io/package/koa-bodyparser.md) ^4.3.0
- [serverless-http](https://npm.io/package/serverless-http.md) ^2.6.0

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 2.1.3 (latest) — 2024-01-19
- 1.1.3 — 2021-04-07
- 1.1.2 — 2021-02-23
- 1.1.1 — 2021-01-21
- 1.0.15 — 2021-01-20
- 1.0.14 — 2021-01-17
- 1.0.13 — 2021-01-13
- 1.0.12 — 2021-01-13
- 1.0.11 — 2021-01-13
- 1.0.10 — 2021-01-11
- 1.0.9 — 2021-01-11
- 1.0.8 — 2021-01-11
- 1.0.7 — 2021-01-10
- 1.0.6 — 2021-01-10
- 1.0.5 — 2021-01-10
- … 5 more at https://npm.io/package/kolp/versions

## README

# Kolp

"jetpack for building microservice on Lambda"

Accronym for Koa on Lambda (Pack). A tiny library toolbox for Lambda (using Koa, Koa Router) then describe your endpoints with controllers.

**Version 2:**

- Updated npm package dependencies to use aws-sdk v3 instead.

## Install

```
npm i --save kolp

# OR

yarn kolp
```

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

## Usage

Start your typescript Lambda project. 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`

```ts
import type { Context } from 'koa'
import { Route, BaseRoutedController } from 'kolp'

export class HelloController extends BaseRoutedController {

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

  @Route()
  async index(context: Context) {
    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`

```ts
import type { Context } from 'koa'
import { RouteMap, BaseRoutedController } from 'kolp'

export class HelloController extends BasedRouteController {

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

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

Now to use these controllers. You will need to map them to paths in the Lambda's handler. Instead of creating your own handler from scratch. Just use `makeServerWithRouter` method to create your handler function.

The function itself allow you to customize the created `router` (Root router). Here is the example.

`handler.ts`

```ts
import 'source-map-support/register'
import { makeServerWithRouter, withJson } from 'kolp'

import { HelloController } from './controllers/hello.controller'

export default makeServerWithRouter((router) => {
  router.prefix('/hello')
    .use(withJson())    // Json error handler!
  
  // Register your controllers here.
  new HelloController().register('/hi', router)
})
```

By the example above. You will be able to:

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

## TODO

```
[ ] Example repo
[ ] Inter Service Communication
[X] SNS/SQS Handler
```

---
_Source: https://npm.io/package/kolp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
