@sgrove/netlify-functions
v0.10.1-beta.0
Published
JavaScript utilities for Netlify Functions
Downloads
30
Readme
JavaScript and TypeScript utilities for Netlify Functions.
Installation
npm install @netlify/functions
Usage
On-demand Builders
To use On-demand Builders, wrap your function handler with the builder
function.
With JavaScript:
const { builder } = require('@netlify/functions') const handler = async (event, context) => { return { statusCode: 200, body: JSON.stringify({ message: 'Hello World' }), } } exports.handler = builder(handler)
With TypeScript:
import { builder, Handler } from '@netlify/functions' const myHandler: Handler = async (event, context) => { return { statusCode: 200, body: JSON.stringify({ message: 'Hello World' }), } } const handler = builder(myHandler) export { handler }
TypeScript typings
This module exports typings for authoring Netlify Functions in TypeScript.
import { Handler } from '@netlify/functions'
const handler: Handler = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello World' }),
}
}
export { handler }
The following types are exported:
Handler
HandlerCallback
HandlerContext
HandlerEvent
HandlerResponse
Contributors
Please see CONTRIBUTING.md for instructions on how to set up and work on this repository. Thanks for contributing!