@rafterjs/lambda
TypeScript icon, indicating that this package has built-in type declarations

0.8.75 • Public • Published

Rafter API Server

The @rafterjs/lambda server provides a simple wrapper around rafter that allows you to execute a single function but still maintain all the benefits that rafter provides including autoloading dependency injection. This is perfect for serverless and CLI applications.

Getting started

yarn add @rafterjs/lambda

Add rafter api to your project

Example structure

  • config
    • config.ts
  • lib
    • MessageController.ts
    • MessageDao.ts
  • index.ts

index.ts

This is the function entry point. So this would be the file that either your CLI or Serverless config would execute.

import { join } from 'path';
import { rafterLambda } from '@rafterjs/lambda';
import { messageController } from './lib/MessageController';

const paths = [join(__dirname, `/{lib,config}/**/`)];

/**
 * This is an example function that benefits from rafter auto dependency injection.
 * This means that you can reuse all the services and code you have written for an API or other apps within a
 * cron job, CLI app or serverless app.
 */
async function run(): Promise<void> {
  await rafterLambda({ paths }, messageController);
}

run();

./lib/MessageController.ts

This is essentially a factory. Rafter injects the dependencies in via the first function, and then returns a new function. The returned function is what rafter uses to execute.

export const messageController = (logger: ILogger) => (): void => {
  logger.info('Hey there, this is a lambda with dependency injection!');
};

Readme

Keywords

none

Package Sidebar

Install

npm i @rafterjs/lambda

Weekly Downloads

15

Version

0.8.75

License

GPL-3.0-or-later

Unpacked Size

64.1 kB

Total Files

52

Last publish

Collaborators

  • crimsonronin