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.

exports.handler = (event, context, callback) => { callback(null, { statusCode: 200, body: "Hello, World ๐Ÿ‘‹๐Ÿป๐Ÿ‡จ๐Ÿ‡ด" }); }; 

Try it out

Hello

Random Emoji ๐Ÿงช

Generating random emoji.

import emoji from 'node-emoji'; export async function handler() { return { statusCode: 200, body: JSON.stringify(emoji.random()) }; } 

Try it out

Emoji

List ๐Ÿถ photos

Generating list dog photos.

For this gallery, we will query a free Unsplash API to obtain super cute images of dogs and display them in a masonry. Head to Unsplash, signup to create a new app and get an access key.

const axios = require('axios') exports.handler = async (event, context, callback) => { const apiRoot = "https://api.unsplash.com" const accessKey = process.env.ACCESS_KEY const collections = `collections='3816141,1154337,1254279'` const clientId = `client_id=${accessKey}` const doggoEndpoint = `${apiRoot}/photos/random?${clientId}&count=${10}&${collections}` try { const res = await axios.get(doggoEndpoint) const result = { statusCode: 200, body: JSON.stringify({ images: res.data} ) } return callback(null, result) } catch (error) { return callback(error); } } 

Try it out

List ๐Ÿถphotos

๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป Developed by khriztianmoreno