Netlify Functions Examples

Hi there! This is a playground to test out Netlify’s Lambda Functions.

You can browse the code for this site on GitHub, or play around with the code yourself deploying a copy to Netlify.

Hello, World!

The inevitable Hello World example.

Try it out

Say hello!

Hello, World! (async version)

The Hello World example can get sweeter with some async syntactic sugar. With async, we can return the response instead of dealing with callbacks.

Try it out

Say hello!

Hello, {name}

Customize the greeting calling the Lambda endpoint with an optional name parameter.

Try it out

Hello, {name} (POST version)

Let’s make sure we only process POST requests for our customized greeting.

Try it out

Show me the error

Read environment variables

Storing secrets like API tokens can be tricky in web apps. Lambdas and environment variables to the rescue!

For this example, I’m defining environment variable "GREETING" in the Netlify site dashboard under Settings > Build & deploy > Build environment variables.

Note: environment variables get baked into your function at deploy time, so you need to trigger a new deploy after you change them.

Try it out

Show me the environment variable