0.1.0 • Published 3 years ago

lambdaware v0.1.0

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

Lambdaware

A simple utility library to add koa-like middlewares to serverless functions. Currently in early development.

Proposed API

import { handleHttpEvent } from 'lambdaware'

const handler = handleHttpEvent([
  ...middleware,
  async (ctx: HttpContext): Promise<void> => {
    // handle event
  }
])

// where HttpContext would look like

type Body = any
type Params = Record<string, any>
type Query = Record<string, any>
type Headers = Record<string, any>

interface Request<B = Body, P = Params, Q = Query, H = Headers> {
  body: B
  params: P
  query: Q
  headers: H
}

interface HttpContext<B, P, Q, H> {
  // parsed request
  req: Request<B, P, Q, H>

  // response
  status: number
  body: any
  headers: any

  // aws raw event
  aws: {
    event: APIGatewayProxyEvent
    context: Context
  }
}