0.0.14 • Published 3 years ago

knative-lambda v0.0.14

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

Async handlers

  1. Define a schema:
// schema.ts

export const event = {
  type: 'object',
  properties: {
    hello: { type: 'string' }
  },
  required: ['hello']
};

export type Event = { hello: string };
  1. Write a handler:
// handler.ts

import { type ServeAsyncHandler } from 'knative-lambda';

import type * as schema from './schema';

export const handler: ServeAsyncHandler<schema.Event> = (event) => {
  console.log('hello', event.hello);
};
  1. Serve:
// index.ts

import { serveAsync } from 'knative-lambda';

import * as schema from './schema';
import { handler } from './handler';

export default serveAsync(handler, schema.event);

Sync handlers

  1. Define a schema:
// schema.ts

const body = {
  type: 'object',
  properties: {
    hello: { type: 'string' }
  },
  required: ['hello']
};

type Body = { hello: string };

export const event = { body };

export type Event = { Body: Body };
  1. Write a handler:
// handler.ts

import { type ServeSyncHandler } from 'knative-lambda';

import type * as schema from './schema';

export const handler: ServeSyncHandler<schema.Event> = (event) => {
  console.log('hello', event.body.hello);
};
  1. Serve:
// index.ts

import { serveSync } from 'knative-lambda';

import * as schema from './schema';
import { handler } from './handler';

export default serveSync(handler, schema.event, { method: 'POST', url: '/' });
0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago